pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: how can I get the length of columns of a table by system tables/views
2+ messages / 2 participants
[nested] [flat]

* Re: how can I get the length of columns of a table by system tables/views
@ 2011-09-09 12:53 shuaixf <shuaixf@gmail.com>
  2011-09-10 05:51 ` Re: Re: how can I get the length of columns of a table by system tables/views msi77 <msi77@yandex.ru>
  0 siblings, 1 reply; 2+ messages in thread

From: shuaixf @ 2011-09-09 12:53 UTC (permalink / raw)
  To: pgsql-sql

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;

--
View this message in context: http://postgresql.1045698.n5.nabble.com/how-can-I-get-the-length-of-columns-of-a-table-by-system-tab...
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Re: how can I get the length of columns of a table by system tables/views
  2011-09-09 12:53 Re: how can I get the length of columns of a table by system tables/views shuaixf <shuaixf@gmail.com>
@ 2011-09-10 05:51 ` msi77 <msi77@yandex.ru>
  0 siblings, 0 replies; 2+ messages in thread

From: msi77 @ 2011-09-10 05:51 UTC (permalink / raw)
  To: shuaixf <shuaixf@gmail.com>; +Cc: pgsql-sql

Why not to use information schema:

select column_name, character_maximum_length from information_schema.columns where table_name ='table name'


09.09.2011, 16:53, "shuaixf" <shuaixf@gmail.com>:
> 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;
>
> --
> View this message in context: http://postgresql.1045698.n5.nabble.com/how-can-I-get-the-length-of-columns-of-a-table-by-system-tab...
> Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-09-10 05:51 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-09 12:53 Re: how can I get the length of columns of a table by system tables/views shuaixf <shuaixf@gmail.com>
2011-09-10 05:51 ` msi77 <msi77@yandex.ru>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox