Monthly Archives: May 2016

How to fix all postgres sequence numbers in a database

Create this stored procedure: CREATE OR REPLACE FUNCTION “reset_sequence” (tablename text, columnname text, sequence_name text) RETURNS “pg_catalog”.”void” AS $body$ DECLARE BEGIN EXECUTE ‘SELECT setval( ”’ || sequence_name || ”’, ‘ || ‘(SELECT MAX(‘ || columnname || ‘) FROM ‘ || … Continue reading

Posted in Uncategorized | Comments Off on How to fix all postgres sequence numbers in a database