Created
October 15, 2012 16:02
-
-
Save nathanjsharpe/3893295 to your computer and use it in GitHub Desktop.
Postgres Reset Sequence Function
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
CREATE OR REPLACE FUNCTION reset_sequence(tablename text) RETURNS "pg_catalog"."void" AS $$ | |
DECLARE | |
BEGIN | |
RAISE NOTICE 'Resetting sequence for %...', tablename; | |
EXECUTE 'SELECT setval(''' || tablename || '_id_seq'', (SELECT MAX(id) FROM ' || tablename || '))'; | |
RAISE NOTICE 'Sequence reset.'; | |
END; | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment