Last active
January 28, 2021 15:12
-
-
Save cdmckay/c0237c8d89872423f660d8243e8289a9 to your computer and use it in GitHub Desktop.
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_to_muid(id varchar) | |
returns varchar as | |
$$ | |
trim(base64_encode( | |
substring(hex_decode_binary(replace(id, '-', '')), 9, 8) || | |
substring(hex_decode_binary(replace(id, '-', '')), 1, 8), | |
0, | |
'-_ ' | |
)) | |
$$; | |
create or replace function muid_to_uuid(id varchar(22)) | |
returns varchar(36) as | |
$$ | |
with uuids as (select | |
hex_encode(substring(base64_decode_binary(id || ' ', '-_ '), 9, 9), 0) || | |
hex_encode(substring(base64_decode_binary(id || ' ', '-_ '), 0, 9), 0) as uuid | |
) | |
select concat(substring(uuid, 0, 8), '-', substring(uuid, 9, 4), '-', substring(uuid, 13, 4), '-', substring(uuid, 17, 4), '-', substring(uuid, 21, 12)) from uuids | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment