Reputation: 75545
Normally, if I want to list columns and types in a table called foo
in the current database, I would use the following SQL statement.
SELECT column_name, data_type
FROM INFORMATION_SCHEMA.COLUMNS
where table_name = 'foo';
However, I want to list the columns in the table INFORMATION_SCHEMA.COLUMNS
, and the following statement returns zero results.
SELECT column_name, data_type
FROM INFORMATION_SCHEMA.COLUMNS
where table_name = 'INFORMATION_SCHEMA.COLUMNS';
What is the correct way to list the columns in the table above, in psql
?
Upvotes: 5
Views: 22098
Reputation:
Tablename and schema name are stored in two columns:
SELECT column_name, data_type
FROM INFORMATION_SCHEMA.COLUMNS
where table_name = 'columns'
and table_schema = 'information_schema';
More details in the manual: http://www.postgresql.org/docs/current/static/infoschema-columns.html
Upvotes: 10