New UUID Formats
ietf.org
ietf.org
CREATE OR REPLACE FUNCTION public.new_uuid_v7ish3()
RETURNS uuid
LANGUAGE sql
AS $function$
SELECT (
lpad(
to_hex(
(
(((extract('epoch' from clock_timestamp()) * 4096) )::bigint << (64-36-12)) --36 bit seconds and 12 bit 4096th of a second
| (7::bigint << (64-36-12-4)) --Version 7
| (random() * 4096)::bigint --12 bit "sequence number"
)
),
16,'0')
||lpad(
to_hex(
(2::bigint << 62) --Variant
+ ((random() * x'4000'::bigint)::bigint << 48) --14 bits of randomness
+ ((random() * x'1000000000000'::bigint)::bigint) --48 bits of randomness
),
16,'0'
)
)::uuid
$function$If you're talking about allocating the same number of bits either way, your way vs their way just expresses a trade between never rolling the random number generator twice for the same entry because you can't generate collisions at different times (theirs) and demanding a uniqueness guarantee for just the random portion on its own and thus re-rolling on collision (yours).
Would subsequently encrypting the time-based IDs before sharing them satisfy your desire to not leak the time information?
I usually include created_at, updated_at, and potentially deleted_at pretty much always in my tables as I don't think they affect storage and performance enough not to considering potential benefits down the line.