4 ms·
Regular old v1 UUIDs contain 60 bits of the system time and are sortable by it, all you need is a uuid library to extract that information from them. Eg, in has
by joeyh 5y ago
Regular old v1 UUIDs contain 60 bits of the system time and are sortable by it, all you need is a uuid library to extract that information from them. Eg, in haskell:
ghci> sortOn Data.UUID.Util.extractTime (map (fromJust . Data.UUID.fromString) ["8fca290c-ac63-11eb-9e74-79cdba6ee3eb", "8d543a32-ac63-11eb-9e74-79cdba6ee3eb"])
[8d543a32-ac63-11eb-9e74-79cdba6ee3eb,8fca290c-ac63-11eb-9e74-79cdba6ee3eb]
- hamandcheese 5y agoNot having the leading bits be the timestamp limits the utility, though, because then you don't get sorting "for free" just by having an index on the ID. At least for me, that is the primary appeal of a time-base UUID.
- saurik 5y agoI always just define a custom comparison operator, which is easy enough in both C++ and PostgreSQL.