Skip to content

Instantly share code, notes, and snippets.

@SomeHats
Last active August 25, 2017 09:13
Show Gist options
  • Save SomeHats/676e0857e91693a691fbe3245c376aca to your computer and use it in GitHub Desktop.
Save SomeHats/676e0857e91693a691fbe3245c376aca to your computer and use it in GitHub Desktop.
with x as (
select clock_timestamp() as t,
gen_random_bytes(3) as r,
1503576000 as offset
),
id as (
select
(((extract(epoch from t) - offset) * 1000)::int8 << 24) |
(get_byte(r, 0) | (get_byte(r, 1) << 8) | (get_byte(r, 2) << 16)) as id
from x
)
select id, encode(int8send(id), 'base64')
from id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment