Created
October 18, 2016 12:04
-
-
Save pintowar/110fa10df996397fc0af0a853a743dec to your computer and use it in GitHub Desktop.
Command to generate commands to update the sequence number of all tables of a postgres database
This file contains hidden or 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 | |
| 'SELECT setval(''' || table_name|| '_id_seq'', COALESCE((SELECT MAX(id)+1 FROM ' || table_name || '), 1), false);' AS command | |
| FROM | |
| information_schema.tables | |
| WHERE | |
| table_type = 'BASE TABLE' | |
| AND | |
| table_schema = 'public'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment