Last active
October 6, 2015 08:20
-
-
Save aamine/0d941e9717d74b3e2328 to your computer and use it in GitHub Desktop.
RedshiftでUUID v4生成
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
select | |
id | |
, replicate('0', 4 - len(w1)) || w1 | |
|| replicate('0', 4 - len(w2)) || w2 | |
|| '-' | |
|| replicate('0', 4 - len(w3)) || w3 | |
|| '-' | |
|| replicate('0', 4 - len(w4)) || w4 | |
|| '-' | |
|| replicate('0', 4 - len(w5)) || w5 | |
|| '-' | |
|| replicate('0', 4 - len(w6)) || w6 | |
|| replicate('0', 4 - len(w7)) || w7 | |
|| replicate('0', 4 - len(w8)) || w8 | |
as visitor_uuid | |
from ( | |
select | |
id | |
, to_hex((random()*65535)::int) as w1 | |
, to_hex((random()*65535)::int) as w2 | |
, to_hex((random()*65535)::int) as w3 | |
, to_hex((random()*65535)::int & 4095 | 16384) as w4 -- & 0x0fff | 0x4000 | |
, to_hex((random()*65535)::int & 16383 | 32768) as w5 -- & 0x3fff | 0x8000 | |
, to_hex((random()*65535)::int) as w6 | |
, to_hex((random()*65535)::int) as w7 | |
, to_hex((random()*65535)::int) as w8 | |
from | |
uuid_test | |
) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment