Created
January 30, 2014 09:25
-
-
Save willgarcia/76ca54fa5827242c8666 to your computer and use it in GitHub Desktop.
postgres drop/truncate table plsql 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
\c metadata | |
CREATE OR REPLACE FUNCTION drop_tables(_schema text) | |
RETURNS void AS | |
$func$ | |
BEGIN | |
EXECUTE ( | |
SELECT 'DROP TABLE ' | |
|| string_agg(quote_ident(t.tablename), ', ') | |
|| ' CASCADE' | |
FROM pg_tables t | |
WHERE t.schemaname = _schema | |
); | |
END | |
$func$ LANGUAGE plpgsql; | |
SELECT drop_tables('public'); | |
DROP FUNCTION IF EXISTS public.drop_tables(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment