From: Tom Lane <tgl@sss.pgh.pa.us>
To: Raghavendra <raghavendra.rao@enterprisedb.com>
Cc: shuaixf <shuaixf@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: how can I get the length of columns of a table by system tables/views
Date: Fri, 09 Sep 2011 09:57:10 -0400
Message-ID: <10512.1315576630@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+h6AhhcnXmvDPXk2XzqRY8W7J+WKmALSen_rMcXT_38=P3_Sw@mail.gmail.com>
References: <1315408840339-4778911.post@n5.nabble.com>
<CA+h6AhhcnXmvDPXk2XzqRY8W7J+WKmALSen_rMcXT_38=P3_Sw@mail.gmail.com>
Raghavendra <raghavendra.rao@enterprisedb.com> writes:
> On Wed, Sep 7, 2011 at 8:50 PM, shuaixf <shuaixf@gmail.com> wrote:
>> 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?
> select pg_column_size(name) from tb;
That would provide the physical size of individual values. I think what
the OP was after was how to get the declared length limit of a column.
That's encoded in pg_attribute.atttypmod. Rather than hard-wiring
knowledge of the way it's encoded, it's best to rely on format_type(),
which knows the rules:
regression=# \d varchar_tbl
Table "public.varchar_tbl"
Column | Type | Modifiers
--------+----------------------+-----------
f1 | character varying(4) |
regression=# select format_type(atttypid, atttypmod) from pg_attribute where attrelid = 'varchar_tbl'::regclass and attname = 'f1';
format_type
----------------------
character varying(4)
(1 row)
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, raghavendra.rao@enterprisedb.com, shuaixf@gmail.com
Subject: Re: how can I get the length of columns of a table by system tables/views
In-Reply-To: <10512.1315576630@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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