https://github.com/budarin/plpgsql-ulid-generator
Function for generating ULID as UUID on plpgsql
https://github.com/budarin/plpgsql-ulid-generator
Last synced: 20 days ago
JSON representation
Function for generating ULID as UUID on plpgsql
- Host: GitHub
- URL: https://github.com/budarin/plpgsql-ulid-generator
- Owner: budarin
- License: mit
- Created: 2022-01-16T07:10:01.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-16T15:49:19.000Z (over 3 years ago)
- Last Synced: 2025-02-17T07:42:17.631Z (4 months ago)
- Language: PLpgSQL
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# plpgsql-ulid-generator
PostgreSQL function for generating ULID as UUID on plpgsql
```sql
select ulid('2022-01-01'); -- 017e12ef-9c00-0000-0000-000000000000
select ulid(); -- 017e61c1-d833-4af7-70c7-8444ae1d207a
```Used for monotonic ids and for partitioning tables using them
```plpgsql
CREATE TABLE "table" (
id uuid primary key not null default ulid(),
...
) partition by range (id);CREATE TABLE table_2021 partition of "table" for values
from
(ulid('2021-01-01'))
to
(ulid('2022-01-01'));
```The UUID format in Postgres is more compact than text as in ULID specification