Created
September 7, 2016 13:58
-
-
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.
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
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