Skip to content

Instantly share code, notes, and snippets.

@klapuch
Last active September 13, 2017 13:37
Show Gist options
  • Save klapuch/bec5cc3de2e232f665c3c13409ec3639 to your computer and use it in GitHub Desktop.
Save klapuch/bec5cc3de2e232f665c3c13409ec3639 to your computer and use it in GitHub Desktop.
CREATE FUNCTION restart_sequences() RETURNS VOID AS $$
DECLARE
public_schema CONSTANT INTEGER NOT NULL DEFAULT 2200;
statements CURSOR FOR SELECT 'ALTER SEQUENCE ' || relname || ' RESTART;' AS query
FROM pg_class
WHERE relkind = 'S'
AND relnamespace = public_schema;
BEGIN
FOR stmt IN statements LOOP
EXECUTE stmt.query;
END LOOP;
END;
$$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment