Created
August 13, 2019 09:18
-
-
Save joduplessis/8f9819b5e34a39b450d589e796213894 to your computer and use it in GitHub Desktop.
PostgreSQL needs to have its Primary Key reset after a table is duplicated - otherwise it runs into the PK ID taken issue. Here's how to reset it to the next highest PK..
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
SELECT setval('TABLENAME_id_seq', (SELECT MAX(id) FROM "TABLENAME")); | |
-- Literally replace TABLENAME with your table name: | |
-- SELECT setval('foo_id_seq', (SELECT MAX(id) FROM "foo")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment