-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Has anyone managed to integrate ULID in PostgreSQL? #41
Comments
I created a domain: CREATE DOMAIN ulid_d AS TEXT CHECK (...); you can check for length, do a full regexp check, etc. |
There is this nasty C extension I made: https://github.com/edoceo/pg-ulid |
@hjr3 I'm confused why you made a domain/text for it. It's just a 16 byte number, and
|
|
You can try take it https://github.com/RPG-18/pg_ulid |
@dharmaturtle how are you generating ulids like that though? Both the jvm and golang ulid generators generate ulids that looks quite different than regular uuids |
@asad-awadia ULIDs are 16 byte numbers, more or less. UUIDs and GUIDs are also 16 byte numbers. However, they're represented differently: UUIDs and GUIDs in hexadecimal with some octet ordering nonsense, and ULIDs as alphanumerics with lexical ordering. I'm gonna emphasize this line from the spec:
I can't speak for the jvm/golang generators, but in C# there's a |
See comparison of ULID generation functions for PostgreSQL |
Is Ulid represented as UUID still sortable ? I am debating between storing them as |
ULIDs and UUIDs are both 128 bits worth of data but they are not compatible with each other. |
Shouldn't storing ULIDs as UUID still work if you are making sure only ULIDs are inserted to that column. It is not ideal for sure but if all your apps are doing the same behavior that should work. If I do that does ordering them work the same? |
Can you Note that "sortable" depends on implementation details. For example, see this or this. UUIDs, unfortunately, have an unintuitive ordering of bytes, which may mess with the implementation of sortable. Note the comment at the end:
So does postgres optimally sort ULIDs? I've no idea. Test it yourself and come back with answers :)
Can you elaborate @peterbourgon? My understanding is that the ULIDs are not UUIDs and UUIDs are not ULIDs for the simple reason that UUIDs have version/variant, and ULIDs do not. Their specs are incompatible. The new draft proposals for UUIDv6, v7, and v8 are compatible with UUIDs though. |
Apologies, my prior comment was imprecise. (The issue I was referring to was that the canonical text encoding of a ULID is via Crockford base32, which produces strings of length 26, but that a Crockford base32 string of length 26 can have a value which is greater than the 128b/16B of a ULID, and therefore invalid.) In fact any arbitrary 128 bits of data will AFAIK always successfully parse as either a ULID or a UUID, so my comment was basically misleading.
It doesn't really matter, I don't think: if you have 16 bytes of data, and those bytes successfully parse as a {ULID, UUID}, then they are a valid {ULID, UUID}. AFAIK the concepts of version/variant/timestamp/etc. exist "above" and independent of validity. |
I have created a new extension called If you look at the README, it covers all the needed features for a proper extension and has a comparison table for all ulid extensions. |
No description provided.
The text was updated successfully, but these errors were encountered: