Skip to content

Instantly share code, notes, and snippets.

@dmshvetsov
Last active September 2, 2019 01:05
Show Gist options
  • Select an option

  • Save dmshvetsov/c1dde732d2572a31c308a9aedcaa8129 to your computer and use it in GitHub Desktop.

Select an option

Save dmshvetsov/c1dde732d2572a31c308a9aedcaa8129 to your computer and use it in GitHub Desktop.
PostgreSQL function to decode relay global IDs and extract local (postgres) ID
-- 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