Skip to content

Instantly share code, notes, and snippets.

@salex89
Created September 7, 2016 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salex89/6726e14bd009bf299468193e2f5b06d0 to your computer and use it in GitHub Desktop.
Save salex89/6726e14bd009bf299468193e2f5b06d0 to your computer and use it in GitHub Desktop.
Stored procedure, drop all entries in all tables in Postgres without dropping or truncating, with optional ignoring.
DECLARE
statements CURSOR FOR
SELECT tablename FROM pg_tables
WHERE tableowner = username AND schemaname = 'public';
BEGIN
FOR stmt IN statements LOOP
IF stmt.tablename != 'algorithm' THEN
EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;';
END IF;
END LOOP;
END;
$$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment