Skip to content

Instantly share code, notes, and snippets.

@michaljemala
Created April 12, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaljemala/6e929d8fe75639e44221bf280c7a3337 to your computer and use it in GitHub Desktop.
Save michaljemala/6e929d8fe75639e44221bf280c7a3337 to your computer and use it in GitHub Desktop.
OID to UUID
CREATE OR REPLACE FUNCTION uuid_from(oid bigint) RETURNS uuid AS $$
BEGIN
RETURN (
lpad(to_hex(oid::bit(64)::bit(32)::integer), 8, '0') ||
'-0000-4000-8000-0000' ||
lpad(to_hex((oid::bit(64)<<32)::bit(32)::integer), 8, '0')
)::uuid;
END;
$$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment