Skip to content

Instantly share code, notes, and snippets.

View ericbrian's full-sized avatar
😀
I am here!

Eric Coffman ericbrian

😀
I am here!
View GitHub Profile
@ericbrian
ericbrian / postgres-update-all-sequenes
Created June 15, 2023 23:19
In Postgres database, update all sequences to max Id.
SELECT
'SELECT SETVAL(' ||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
FROM
pg_class AS S,
pg_depend AS D,
pg_class AS T,
pg_attribute AS C,