Skip to content

Instantly share code, notes, and snippets.

@iljya
Created February 6, 2022 18:01
Show Gist options
  • Save iljya/5b4c7a8eef4973e3ab5f22ae196458b4 to your computer and use it in GitHub Desktop.
Save iljya/5b4c7a8eef4973e3ab5f22ae196458b4 to your computer and use it in GitHub Desktop.
-- Create a query to delete all tables with a certain field name.
select array_to_string(array_agg(cmd), '; ') from (
select concat('DROP TABLE "', t.table_name, '"') as cmd
from information_schema.tables t
inner join information_schema.columns c on c.table_name = t.table_name
and c.table_schema = t.table_schema
where c.column_name = 'geometry'
and t.table_schema not in ('information_schema', 'pg_catalog')
and t.table_type = 'BASE TABLE'
order by t.table_schema) as cmds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment