RPG-18 / pg_ulid

Universally Unique Lexicographically Sortable Identifier generate for PostgreSQL
MIT License
11 stars 0 forks source link

Add an input timestamp parameter to ulid_generate #7

Open budarin opened 2 years ago

budarin commented 2 years ago

To generate a check constraint for partitioning tables, it is necessary to be able to create an ulid for a specific datetime like so:

CREATE TABLE "table" (
  id uuid primary key not null default ulid_generate(),
  ...
) partition by range (id);

CREATE TABLE table_2021 partition of "table" for values
  from 
        ulid_generate('2021-01-01 00:00:00')     --0176bb3e-7000-0000-0000-000000000000
  to 
        ulid_generate('2022-01-01 00:00:00');    --017e12ef-9c00-0000-0000-000000000000

(it is also possible with the random part of ulid - it does not matter much)