0

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 2

0
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'my_view';
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.