Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created October 19, 2012 16:23
Show Gist options
  • Save hgdeoro/3919157 to your computer and use it in GitHub Desktop.
Save hgdeoro/3919157 to your computer and use it in GitHub Desktop.
Truncate all the tables of 'public' schema
CREATE OR REPLACE FUNCTION truncate_all_tables() RETURNS void AS $$
DECLARE
stmt RECORD;
statements CURSOR FOR SELECT tablename from pg_tables where schemaname = 'public';
BEGIN
FOR stmt IN statements LOOP
EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
END LOOP;
END;
$$ LANGUAGE 'plpgsql';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment