diff --git a/contrib/uuid-ossp/Makefile b/contrib/uuid-ossp/Makefile index c52c583d64..7f29bec535 100644 --- a/contrib/uuid-ossp/Makefile +++ b/contrib/uuid-ossp/Makefile @@ -4,7 +4,7 @@ MODULE_big = uuid-ossp OBJS = uuid-ossp.o $(UUID_EXTRA_OBJS) $(WIN32RES) EXTENSION = uuid-ossp -DATA = uuid-ossp--1.1.sql uuid-ossp--1.0--1.1.sql uuid-ossp--unpackaged--1.0.sql +DATA = uuid-ossp--1.1.sql uuid-ossp--1.0--1.1.sql uuid-ossp--1.1--1.2.sql uuid-ossp--unpackaged--1.0.sql PGFILEDESC = "uuid-ossp - UUID generation" REGRESS = uuid_ossp diff --git a/contrib/uuid-ossp/uuid-ossp--1.1--1.2.sql b/contrib/uuid-ossp/uuid-ossp--1.1--1.2.sql new file mode 100644 index 0000000000..8e47ca60a1 --- /dev/null +++ b/contrib/uuid-ossp/uuid-ossp--1.1--1.2.sql @@ -0,0 +1,9 @@ +/* contrib/uuid-ossp/uuid-ossp--1.1--1.2.sql */ + +-- complain if script is sourced in psql, rather than via ALTER EXTENSION +\echo Use "ALTER EXTENSION uuid-ossp UPDATE TO '1.2'" to load this file. \quit + +CREATE FUNCTION uuid_version(namespace uuid) +RETURNS int4 +AS 'MODULE_PATHNAME', 'uuid_version' +IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE; diff --git a/contrib/uuid-ossp/uuid-ossp.c b/contrib/uuid-ossp/uuid-ossp.c index f5ae915f24..b4997281c0 100644 --- a/contrib/uuid-ossp/uuid-ossp.c +++ b/contrib/uuid-ossp/uuid-ossp.c @@ -122,6 +122,7 @@ PG_FUNCTION_INFO_V1(uuid_generate_v1mc); PG_FUNCTION_INFO_V1(uuid_generate_v3); PG_FUNCTION_INFO_V1(uuid_generate_v4); PG_FUNCTION_INFO_V1(uuid_generate_v5); +PG_FUNCTION_INFO_V1(uuid_version); #ifdef HAVE_UUID_OSSP @@ -531,3 +532,16 @@ uuid_generate_v5(PG_FUNCTION_ARGS) VARDATA_ANY(name), VARSIZE_ANY_EXHDR(name)); #endif } + +Datum +uuid_version(PG_FUNCTION_ARGS) +{ + pg_uuid_t *arg = PG_GETARG_UUID_P(0); + dce_uuid_t uu; + + /* function is marked STRICT, so arg can't be NULL */ + memcpy(&uu,arg,UUID_LEN); + UUID_TO_NETWORK(uu); + + PG_RETURN_INT32(uu.time_hi_and_version >> 12); +} diff --git a/contrib/uuid-ossp/uuid-ossp.control b/contrib/uuid-ossp/uuid-ossp.control index 657476c182..3479b06eff 100644 --- a/contrib/uuid-ossp/uuid-ossp.control +++ b/contrib/uuid-ossp/uuid-ossp.control @@ -1,5 +1,5 @@ # uuid-ossp extension comment = 'generate universally unique identifiers (UUIDs)' -default_version = '1.1' +default_version = '1.2' module_pathname = '$libdir/uuid-ossp' relocatable = true diff --git a/doc/src/sgml/uuid-ossp.sgml b/doc/src/sgml/uuid-ossp.sgml index b3b816c372..43dd565886 100644 --- a/doc/src/sgml/uuid-ossp.sgml +++ b/doc/src/sgml/uuid-ossp.sgml @@ -156,6 +156,22 @@ SELECT uuid_generate_v3(uuid_ns_url(), 'http://www.postgresql.org'); + +