4 ms·
I like ordered UUIDs, but if you care about 100% strict and accurate ordering you need to be careful about generating them in app code vs. on the DB side. With
by solicode 6y ago
I like ordered UUIDs, but if you care about 100% strict and accurate ordering you need to be careful about generating them in app code vs. on the DB side. With the former + using multiple app servers, server clock drift can become an issue. Which is why I still generate my ordered UUIDs on my Postgres server. It means writing some funky PL/pgSQL (or however you decide to do it... I think you can run Python too), but it gets the job done.
I wish ordered UUIDs were built-in to more DBs natively. I remember seeing UUIDv6 being proposed, but I don't know if/when that will be standardised.
- httgp 6y agoHow does one generate ordered UUIDs right on the PostgreSQL server?
- solicode 6y agoThere's probably a nicer way (or more performant at least), but I created a function that uses the built-in `uuid_generate_v1mc` and then reverse the order of the time component so that high values come first.
- Tostino 6y agoUse this: https://github.com/tvondra/sequential-uuids https://github.com/tvondra/sequential-uuids If you cannot install extensions, I just wrote a PL/PGSQL implementation for the time-based generator I could share.