Skip to content

Instantly share code, notes, and snippets.

@theart84
theart84 / fn_uuid_time_ordered.sql
Created February 22, 2023 04:35 — forked from fabiolimace/UUIDv6.sql
Function for generating time-ordered UUIDs (UUIDv6) on PostgreSQL
/**
* Returns a time-ordered UUID (UUIDv6).
*
* Tags: uuid guid uuid-generator guid-generator generator time order rfc4122 rfc-4122
*/
create or replace function fn_uuid_time_ordered() returns uuid as $$
declare
v_time timestamp with time zone:= null;
v_secs bigint := null;
v_usec bigint := null;