Skip to content

Instantly share code, notes, and snippets.

View phanmn's full-sized avatar

phanmn

  • Ho Chi Minh city, Viet Nam
View GitHub Profile
@phanmn
phanmn / snowflake-id.sql
Created July 31, 2024 10:26 — forked from beginor/snowflake-id.sql
Twitter Snowflake ID for PostgreSQL
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;