How to retreive data type, size, precision and scale of all columns of a particular table in postgresql with a single sql statement?
The table can have columns of the data types ( 'int2','int4','int8','float4','float8','numeric','v开发者_高级运维archar','char','date','timestamp'). If precision/scale are not applicable for a particular data type we can leave it as null.
I should not use INFORMATION_SCHEMA for this because though this schema is built-in we can drop this schema. SO i wrote code using this schema and if some how the customer drops this schema my code breaks. I just want to use pg_catalog
tables/views.
The tables in information_schema are views on the system tables. If you use this command in psql, you will get the view definition that generates the columns view:
\dS+ information_schema.columns
You'll still have some work to do as the type casts to user-friendly outputs are also based on information_schema, but that shouldn't be too hard.
EDIT: In versions prior to 8.4, you have to use \d+, not \dS+
精彩评论