Created
October 21, 2022 05:01
-
-
Save kilfu0701/23d5318fd0e14962d08cb8cbe145e709 to your computer and use it in GitHub Desktop.
Postgres ctid to bigint converter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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