Awesome
<img src="https://github.com/user-attachments/assets/46a5c546-7e9b-42c7-87f4-bc8defe674e0" width=250 />DuckDB TSID Community Extension
This extension adds support for Time-Sorted Unique Identifiers (TSID)
Experimental: USE AT YOUR OWN RISK!
š¦ Installation
INSTALL tsid FROM community;
LOAD tsid;
Usage
Generate a new TSID:
-- Generate a new time-sortable ID (accepts an optional seed string)
D SELECT tsid();
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā tsid() ā
ā varchar ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā 675716e86985495e9cf575f0b9c4a8db ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Working with Timestamps
Extract the timestamp from a TSID:
-- Extract timestamp from a TSID
D SELECT tsid_to_timestamp('675716e86985495e9cf575f0b9c4a8db');
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā tsid_to_timestamp('675716e86985495e9cf575f0b9c4a8db') ā
ā timestamp ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā 2024-12-09 16:12:24.44259 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
-- Verify TSID ordering
D SELECT
a.id as id1,
b.id as id2,
tsid_to_timestamp(a.id) as ts1,
tsid_to_timestamp(b.id) as ts2
FROM
(SELECT tsid('a') as id FROM range(1)) a,
(SELECT tsid('b') as id FROM range(1)) b;
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā id1 ā id2 ā ts1 ā ts2 ā
ā varchar ā varchar ā timestamp ā timestamp ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāāāāāā¤
ā 6757176b9d4640b299be06ff79ed1373 ā 6757176b9d704dcf8a1dce8bb6da51bf ā 2024-12-09 16:14:35.659653 ā 2024-12-09 16:14:35.660354 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Bulk Generation
Generate multiple TSIDs:
-- Generate 100 sequential unique TSIDs
D SELECT tsid(random()::VARCHAR) as unique_id
FROM range(100);
Features
- Time-sortable: TSIDs are chronologically sortable by string comparison
- Unique: Each ID is guaranteed to be unique
- Timestamp extraction: Get the creation time of any TSID
- High performance: Suitable for bulk generation