PostgreSQL - Check where a column name is used in all schemas.

SQL

·

1 min read

If you want to discover where a column name is used in all schemas of your database, it is quite simple. Only run the script below replacing the the_name_of_column_you_want_find with the name you wish.

select t.table_schema, t.table_name
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 = 'the_name_of_column_you_want_find'
      and t.table_schema not in ('information_schema', 'pg_catalog')
      and t.table_type = 'BASE TABLE'
order by t.table_schema;