diff --git a/contrib/uuid-ossp/uuid-ossp--1.1.sql b/contrib/uuid-ossp/uuid-ossp--1.1.sql index c9cefd7360..a2eb217fd8 100644 --- a/contrib/uuid-ossp/uuid-ossp--1.1.sql +++ b/contrib/uuid-ossp/uuid-ossp--1.1.sql @@ -52,3 +52,8 @@ CREATE FUNCTION uuid_generate_v5(namespace uuid, name text) RETURNS uuid AS 'MODULE_PATHNAME', 'uuid_generate_v5' IMMUTABLE STRICT LANGUAGE C PARALLEL SAFE; + +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/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'); + +