#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);