Skip to content

Instantly share code, notes, and snippets.

@aamine
Last active October 6, 2015 08:20
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 aamine/0d941e9717d74b3e2328 to your computer and use it in GitHub Desktop.
Save aamine/0d941e9717d74b3e2328 to your computer and use it in GitHub Desktop.
RedshiftでUUID v4生成
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