Skip to content

Postgres helper functions for converting between ULID and UUID.

License

Notifications You must be signed in to change notification settings

scoville/pgsql-ulid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

pgsql-ulid

Postgres helper functions for converting between ULID and UUID.

Your application layer may deal exclusively with transformation of ULIDs, so what do you do when you need to query your DB for something? That's where these handy functions come in!

Example

https://dbfiddle.uk/?rdbms=postgres_9.6&fiddle=e55e8cb2541a73034bf573f7318b40c5

Usage

ulid_to_uuid(ulid text) RETURNS uuid

Takes a ULID string and returns a UUID.

SELECT ulid_to_uuid('01FGB414J8PPBVHBMHGSXGS21C');

-- 017c1640-9248-b597-b8ae-91867b0c882c

uuid_to_ulid(id uuid) RETURNS text

Takes a UUID and returns a ULID string.

SELECT uuid_to_ulid('017c1640-9248-b597-b8ae-91867b0c882c');

-- 01FGB414J8PPBVHBMHGSXGS21C

parse_ulid(ulid text) RETURNS bytea

Takes a ULID string and returns a Byte Array. In case you need the raw bytes for something else.

Inspirations

About

Postgres helper functions for converting between ULID and UUID.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published