fboulnois / pg_uuidv7

A tiny Postgres extension to create version 7 UUIDs
Mozilla Public License 2.0
298 stars 25 forks source link

Add ability to extract the timestamp from uuid value #6

Closed k-bx closed 1 year ago

k-bx commented 1 year ago

Would be nice to have a simple function that could extract the timestamp part of the uuidv7 value.

For now, I've found this ugly hack:

SELECT to_timestamp(('x' || ltrim((decode(replace(uuid_generate_v7()::text, '-', ''), 'hex'))::text, '\x'))::bit(48)::bigint / 1000);
fboulnois commented 1 year ago

Check out version 1.1.0, I added the uuid_v7_to_timestamptz function.

k-bx commented 1 year ago

Perfect, thank you!