Skip to content

Instantly share code, notes, and snippets.

View dsmontoya's full-sized avatar
:shipit:
Available

Daniel Montoya dsmontoya

:shipit:
Available
  • México
View GitHub Profile
@fabiolimace
fabiolimace / fn_tsid_milli.sql
Last active October 16, 2024 09:00
Function for generating Time Sortable ID with millisecond precision on PostgreSQL
/**
* Returns a Time Sortable ID with millisecond precision.
*
* Time component: 42 bits (2^42 = ~69 years)
*
* Random component: 22 bits (2^22 = 4,194,304)
*
* The time component is the count of milliseconds since 2020-01-01T00:00:00Z.
*
* Tags: tsid ulid snowflake id-generator generator time sortable sort order id