Created
August 6, 2015 23:58
-
-
Save iver/5ca8be52858c2f24a9ba to your computer and use it in GitHub Desktop.
Update sequence query
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 pg_catalog.setval(pg_get_serial_sequence('''|| | |
pg_class.relname || ''', ''' || | |
pg_attribute.attname || '''), (SELECT MAX(' || pg_attribute.attname || ') FROM ' || | |
pg_class.relname || ') +1 ); ' | |
FROM pg_index, pg_class, pg_attribute | |
WHERE | |
pg_class.oid = pg_class.relname::regclass AND | |
indrelid = pg_class.oid AND | |
pg_attribute.attrelid = pg_class.oid AND | |
pg_attribute.attnum = any(pg_index.indkey) AND | |
pg_class.relkind = 'r' and pg_class.relhaspkey | |
AND indisprimary | |
AND pg_class.relname LIKE '<table_name>' | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment