File: pg_uuidv7--1.7.sql

package info (click to toggle)
pg-uuidv7 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 248 kB
  • sloc: ansic: 86; sql: 82; sh: 17; makefile: 13
file content (32 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use '''CREATE EXTENSION "pg_uuidv7"''' to load this file. \quit

-- 48 bits for ms since unix epoch (rollover in 10899), 74 bits of randomness
CREATE FUNCTION uuid_generate_v7()
RETURNS uuid
AS 'MODULE_PATHNAME', 'uuid_generate_v7'
VOLATILE STRICT LANGUAGE C PARALLEL SAFE;

-- extract the timestamptz from a v7 uuid
CREATE FUNCTION uuid_v7_to_timestamptz(uuid)
RETURNS timestamptz
AS 'MODULE_PATHNAME', 'uuid_v7_to_timestamptz'
STABLE STRICT LANGUAGE C PARALLEL SAFE;

-- create a v7 uuid from a timestamptz
CREATE FUNCTION uuid_timestamptz_to_v7(timestamptz, zero bool = false)
RETURNS uuid
AS 'MODULE_PATHNAME', 'uuid_timestamptz_to_v7'
STABLE STRICT LANGUAGE C PARALLEL SAFE;

-- extract the timestamp from a v7 uuid
CREATE FUNCTION uuid_v7_to_timestamp(uuid)
RETURNS timestamp
AS 'MODULE_PATHNAME', 'uuid_v7_to_timestamp'
STABLE STRICT LANGUAGE C PARALLEL SAFE;

-- create a v7 uuid from a timestamp
CREATE FUNCTION uuid_timestamp_to_v7(timestamp, zero bool = false)
RETURNS uuid
AS 'MODULE_PATHNAME', 'uuid_timestamp_to_v7'
STABLE STRICT LANGUAGE C PARALLEL SAFE;