Hi, I’m Dung Huynh Duc . Nice to meet you.

About Me

With over a decade of experience under my belt as a full-stack developer, I've had the opportunity to spearhead project teams at tech startups in Vietnam, Thailand, Japan and Singapore. Additionally, I have worked as a freelance engineer for various companies based in Asia Pacific, Europe, and North America.

Presently, I serve the role of a Senior Full Stack Software Engineer at ACX. I am consistently committed to exploring and acquiring knowledge on emerging and popular technologies.

PostgreSQL.
db

#TIL 21 - How to fix PostgreSQL duplicate key violates (out of sync)

blog_hero_#TIL 21 - How to fix PostgreSQL duplicate key violates (out of sync)

Why

For some reason, we could have an issue with the primary key auto-generated.

How

Check the next primary key value

SELECT nextval('public.source_id_seq'), MAX(id) FROM "source";

Then adjust the value

 SELECT SETVAL((SELECT PG_GET_SERIAL_SEQUENCE('"source"', 'id')), (SELECT (MAX("id") + 1) FROM "source"), FALSE);