Re: Getting lengths of variable fields

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Michelle Murrain <mpm(at)norwottuck(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Getting lengths of variable fields
Date: 2001-03-05 22:55:04
Message-ID: 21303.983832904@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Michelle Murrain writes:
>> Is there something I am missing? Is there a way to get the size of variable
>> length types using DBI/DBD::Pg, in particular, char() and varchar()?

> Normally, you'd use LENGTH or OCTET_LENGTH. If you want to get the
> storage size on disk, you could add 4 to what you get as length, but this
> result seems to be of dubious value, especially with TOAST (compression,
> out-of-line storage).

What Michelle seems to want is the declared limit on field width, not
the actual width of any particular value.

This info is stored in the 'atttypmod' field of pg_attribute, but I
don't know whether DBD::Pg provides any handy interface to that. You
might have to get down-and-dirty enough to select it directly out of
pg_attribute ...

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Juan R. Cortabitarte 2001-03-05 22:55:10 Re: Re: RPMs for PHP accessing PostgreSQL via ODBC over RedHat
Previous Message Peter Eisentraut 2001-03-05 22:52:49 Re: upper() vs. lower()