If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
how can I get the length of columns of a table by system tables/views
According to pg_class, pg_attribute, pg_type, I can get the tablename, column name, column type
however, how to get the length of columns of a table by system tables/views? Thanks!
SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = (SELECT pg_class.oid
FROM pg_class INNER JOIN pg_namespace
ON (pg_class.relnamespace = pg_namespace.oid
AND lower(pg_namespace.nspname) = 'public')
WHERE pg_class.relname='tablename')
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum;