Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011
    Posts
    4

    Unanswered: 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!

  2. #2
    Join Date
    Aug 2011
    Posts
    4
    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •