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 SEQUENCE IF NOT EXISTS public.snowflake_id_seq | |
MINVALUE 0 MAXVALUE 1023 | |
CYCLE; | |
ALTER SEQUENCE public.global_id_seq OWNER TO postgres; | |
-- 41 bits for time in milliseconds | |
-- (41 years of IDs from epoch) | |
-- 13 bits for the logical shard ID | |
-- 10 bits for the global auto-incrementing sequence (modulus 1024). | |
-- This means we can generate 1024 IDs, per shard, per millisecond |
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 SEQUENCE public.global_id_seq; | |
ALTER SEQUENCE public.global_id_seq OWNER TO postgres; | |
CREATE OR REPLACE FUNCTION public.id_generator() | |
RETURNS bigint | |
LANGUAGE 'plpgsql' | |
AS $BODY$ | |
DECLARE | |
our_epoch bigint := 1314220021721; | |
seq_id bigint; |