Skip to content

Instantly share code, notes, and snippets.

@willgarcia
Created January 30, 2014 09:25
Show Gist options
  • Save willgarcia/76ca54fa5827242c8666 to your computer and use it in GitHub Desktop.
Save willgarcia/76ca54fa5827242c8666 to your computer and use it in GitHub Desktop.
postgres drop/truncate table plsql function
\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