Created
April 12, 2018 12:21
-
-
Save michaljemala/6e929d8fe75639e44221bf280c7a3337 to your computer and use it in GitHub Desktop.
OID to UUID
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
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