Skip to content

Inspection functions in the TSID DuckDB extension

Sample data for the examples

Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.

-- Fixtures for tsid cookbook / functions / technical-details examples.
-- Idempotent: uses CREATE OR REPLACE so re-running is safe.
--
-- tsid() is non-deterministic, so we seed the events table with literal
-- 32-char hex strings (the TSID rendering) rather than calling tsid().
-- The values are time-ordered by ordinary string compare, matching the
-- property the cookbook examples demonstrate.

CREATE OR REPLACE TABLE events (
  id      VARCHAR PRIMARY KEY,
  payload JSON
);

INSERT INTO events(id, payload) VALUES
  ('675716e86985495e9cf575f0b9c4a8db', '{"type":"login"}'),
  ('675716e96985495e9cf575f0b9c4a8dc', '{"type":"click"}'),
  ('675716ea6985495e9cf575f0b9c4a8dd', '{"type":"logout"}');

-- Bind variable referenced as :last_id_from_page_1 in the pagination recipe.
SET VARIABLE last_id_from_page_1 = '675716ea6985495e9cf575f0b9c4a8dd';

Function category

Inspection

1 function

tsid_to_timestamp

Scalar function Inspection
Signature
tsid_to_timestamp(tsid: VARCHAR | UUID) → TIMESTAMP
Arguments (Positional)
Argument tsid Type VARCHAR | UUID
2 concrete types
UUIDVARCHAR
Mode Positional Description
Description
1 Recover when a row was inserted from its id alone
SELECT id, tsid_to_timestamp(id) AS created_at FROM events;
2 Known value, undashed and dashed forms
SELECT tsid_to_timestamp('65d4a2b6000000004000800000000000') AS a,
       tsid_to_timestamp('65d4a2b6-0000-0000-4000-800000000000') AS b;
3 DuckDB 2.0 build: decode a native UUID
SELECT tsid_to_timestamp('65d4a2b6-0000-0000-4000-800000000000'::UUID) AS created_at;
4 Malformed input becomes NULL with TRY
SELECT TRY(tsid_to_timestamp('not-a-tsid')) AS created_at;