how to add ulid compatibility to postgres?

Is there a way to create a custom ulid type with postgres to use as a primary key? it could either be automatically generated from the database side or passed in from the client. it was easy enough to create a custom type using mysql that was essentially just a char(26), however im trying to implement something a little closer to this article - https://blog.daveallie.com/ulid-primary-keys. any advice would be greatly appreciated. This is also in the context of having a supabase postgres instance.
1 Reply
BinaryArtifex
BinaryArtifexOP11mo ago
now that i think about it, ive been downa bit of a rabbit hole about how best to store ulid's in a postgres database and without needlessly bloating primary keys (via varchar(26)) and still have the nicety of sortable indexing so i think im gonna drop the whole ulid thing in favor of uuidv7. there's currently a good npm lib at https://github.com/LiosK/uuidv7 that looks like a good candidate...
GitHub
GitHub - LiosK/uuidv7: An experimental implementation of the propos...
An experimental implementation of the proposed UUID Version 7 - GitHub - LiosK/uuidv7: An experimental implementation of the proposed UUID Version 7
Want results from more Discord servers?
Add your server