You can query the database's information_schema. columns table which holds the schema structure of all columns defined in your database. The result would give you the columns: TABLE_NAME , TABLE_CATALOG , DATA_TYPE and more properties for this database column.
Use the \dt or \dt+ command in psql to show tables in a specific database. Use the SELECT statement to query table information from the pg_catalog. pg_tables catalog.
You can also do
select table_name from information_schema.columns where column_name = 'your_column_name'
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
I've used the query of @Roman Pekar as a base and added schema name (relevant in my case)
select n.nspname as schema ,c.relname
from pg_class as c
inner join pg_attribute as a on a.attrelid = c.oid
inner join pg_namespace as n on c.relnamespace = n.oid
where a.attname = 'id_number' and c.relkind = 'r'
sql fiddle demo
Simply:
$ psql mydatabase -c '\d *' | grep -B10 'mycolname'
Enlarge -B offset to get table name, if need
Wildcard Support Find the table schema and table name that contains the string you want to find.
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 like '%STRING%'
and t.table_schema not in ('information_schema', 'pg_catalog')
and t.table_type = 'BASE TABLE'
order by t.table_schema;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With