Hasan Iqbal Anik Hasan Iqbal Anik - 1 year ago 61
SQL Question

How to find a table having a specific column in postgresql

I'm using postgresql 9.1. I have the column name of a table. Is it possible to find the table(s) that has/have this column? How? Thanks in advance.

Answer Source

you can query system catalogs:

select c.relname
from pg_class as c
    inner join pg_attribute as a on a.attrelid = c.oid
where a.attname = <column name> and c.relkind = 'r'

sql fiddle demo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download