Find PostgreSQL tables with column name


This post goes over how to find PostgreSQL tables with a column name.

INFORMATION_SCHEMA

Find all PostgreSQL tables with the column name foo:

SELECT TABLE_NAME, COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'foo';

See “Find MySQL tables with column name”.

pg_class

Find all PostgreSQL tables with the column name foo:

SELECT pg_class.relname
FROM pg_class
JOIN pg_attribute ON pg_attribute.attrelid = pg_class.oid
WHERE pg_attribute.attname = 'foo'
AND pg_class.relkind = 'r';


Please support this site and join our Discord!