Skip to content

Instantly share code, notes, and snippets.

@kilfu0701
Created October 21, 2022 05:01
Show Gist options
  • Save kilfu0701/23d5318fd0e14962d08cb8cbe145e709 to your computer and use it in GitHub Desktop.
Save kilfu0701/23d5318fd0e14962d08cb8cbe145e709 to your computer and use it in GitHub Desktop.
Postgres ctid to bigint converter.
-- https://stackoverflow.com/questions/26279770/how-to-cast-ctid-system-column-into-long-and-vice-versa
-- ctid to long
SELECT ((ctid::text::point)[0]::bigint << 32) | (ctid::text::point)[1]::bigint AS long_ctid FROM table1 LIMIT 1;
long_ctid
-----------------
130043019788289
(1 row)
-- long to ctid
SELECT CONCAT('(', long_ctid >> 32,',',long_ctid << 32 >> 32,')')::tid ;
SELECT CONCAT('(', 130043019788289 >> 32,',',130043019788289 << 32 >> 32,')')::tid ;
concat
-----------
(30278,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment