After reviewing min_uuid_v7 I understood the bug setting the UUID version bits in my first attempt.
I suggest this fixed version:
CREATE OR REPLACE FUNCTION min_uuid_v7(min_timestamp timestamp) RETURNS uuid
LANGUAGE sql immutable strict
AS $function$
SELECT encode(
overlay('\x00000000000070000000000000000000'::bytea
placing substring(int8send(floor(extract(epoch from min_timestamp) * 1000)::bigint) from 3)
from 1 for 6)
, 'hex')::uuid;
$function$;
The value simply starts with the version bits already set before overlaying with the timestamp. set_bit calls are not needed.
After reviewing
min_uuid_v7
I understood the bug setting the UUID version bits in my first attempt. I suggest this fixed version:The value simply starts with the version bits already set before overlaying with the timestamp.
set_bit
calls are not needed.