Skip to content

Instantly share code, notes, and snippets.

@tonatiuh
Created July 30, 2013 22:06
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 tonatiuh/6117475 to your computer and use it in GitHub Desktop.
Save tonatiuh/6117475 to your computer and use it in GitHub Desktop.
Reset db on psql
SELECT
'DROP TABLE '||c.relname ||' CASCADE;'
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_roles r ON r.oid = c.relowner
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment