-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: a new script is now available to update the auto increment columns
- Loading branch information
1 parent
b32f65b
commit 13378b3
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
DO $$ | ||
DECLARE | ||
r RECORD; | ||
BEGIN | ||
FOR r IN | ||
SELECT | ||
table_name, | ||
column_name, | ||
substring(column_default FROM 'nextval\(''(.*)''::regclass\)') AS sequence_name | ||
FROM | ||
information_schema.columns | ||
WHERE | ||
column_default LIKE 'nextval%' | ||
LOOP | ||
EXECUTE 'SELECT setval(''' || r.sequence_name || ''', COALESCE((SELECT MAX(' || r.column_name || ') FROM ' || r.table_name || '), 1));'; | ||
END LOOP; | ||
END $$; |