3 ms·
How would one go about trying to use UUID 7 in a Postgres database / python codebase now?
by canadiantim 4y ago
How would one go about trying to use UUID 7 in a Postgres database / python codebase now?
- oittaa 4y agoI made a simple Python test library that extends the standard UUID class with UUIDv6 and UUIDv7. You might want to check it out. https://github.com/oittaa/uuid6-python https://github.com/oittaa/uuid6-python The official UUID Draft repository has also some alternatives if you'd like to check those out. https://github.com/uuid6/prototypes https://github.com/uuid6/prototypes Postgres supports UUIDs with any version number natively so you can then do something like this with it: create table data (id uuid, firstname varchar(100)); insert into data (id, firstname) values ('017f21cf-d130-7cc3-98c4-dc0c0c07398f', 'John'); select * from data;
- Starlevel001 4y agoPostgres UUIDs are treated as an opaque 8-byte array, you can use anything as long as it's in the textual format.
- kjmph 4y agoI created a PL/pgSQL function for this purpose. As Starlevel001 mentioned, the UUID format will accept opaque bytes. Perhaps you could find this useful? https://gist.github.com/kjmph/5bd772b2c2df145aa645b837da7eca74 https://gist.github.com/kjmph/5bd772b2c2df145aa645b837da7eca...
- stevesimmons 4y agoMy Python implementation is here: https://github.com/stevesimmons/uuid7 https://github.com/stevesimmons/uuid7 https://pypi.org/project/uuid7/ https://pypi.org/project/uuid7/
- oittaa 4y agoNice to see another implementation which takes a bit different approach. Just for your information, there's now Draft 03 which changes the format a little bit. I kinda liked the arbitrary precision of Draft 02, but the newer one just requires millisecond precision and then basically leaves it up to the implementation how to handle the generation of multiple UUIDs within the same millisecond. https://github.com/uuid6/prototypes/issues/21 https://github.com/uuid6/prototypes/issues/21