Last active
September 2, 2019 01:05
-
-
Save dmshvetsov/c1dde732d2572a31c308a9aedcaa8129 to your computer and use it in GitHub Desktop.
PostgreSQL function to decode relay global IDs and extract local (postgres) ID
This file contains hidden or 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
| -- Usage: | |
| -- select * from users where id = to_locid('VXNlcjozNg=='); | |
| create or replace function to_locid(globid text) returns int as $$ | |
| begin | |
| return (split_part(encode(decode(globid, 'base64'), 'escape'), ':', 2))::int; | |
| end; | |
| $$ language plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment