-
-
Save heijmerikx/b3e7958be03bd7f34ee4bd8f46ed040c to your computer and use it in GitHub Desktop.
reset all sequences on a postgres db
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 'SELECT SETVAL(' ||quote_literal(S.relname)|| ', MAX(' ||quote_ident(C.attname)|| ') ) FROM ' ||quote_ident(T.relname)|| ';' | |
FROM pg_class AS S, pg_depend AS D, pg_class AS T, pg_attribute AS C | |
WHERE S.relkind = 'S' | |
AND S.oid = D.objid | |
AND D.refobjid = T.oid | |
AND D.refobjid = C.attrelid | |
AND D.refobjsubid = C.attnum | |
ORDER BY S.relname; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment