I want to get meta information of a view in postgres. Specifically the column data types. Any suggestion for how to do that?
2 Answers
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'my_view';
You should use the following query:
SELECT attname AS column_name, format_type(atttypid, atttypmod) AS data_type
FROM pg_attribute
WHERE attrelid = 'your_schema.table_or_view_name'::regclass
-- AND NOT attisdropped
-- AND attnum > 0
ORDER BY attnum;
As query on information_schema.columns
will show citext
and other extension based types as USER-DEFINED
while the following query will show the correct type e.g. citext
.