Skip to content

Instantly share code, notes, and snippets.

Avatar

Caleb Johnson calebj

View GitHub Profile
@beginor
beginor / snowflake-id.sql
Last active Oct 11, 2021
Twitter Snowflake ID for PostgreSQL
View snowflake-id.sql
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;