Re: Getting lengths of variable fields

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Michelle Murrain <mpm(at)norwottuck(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Getting lengths of variable fields
Date: 2001-03-05 22:40:57
Message-ID: Pine.LNX.4.30.0103052338120.777-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michelle Murrain writes:

> I'm writing a very robust validation script in perl for database entry. One
> of the things I'd like to do is check how large a field is, and make sure
> that the entry into that field isn't too big. Problem is, for variable length
> fields, DBD::Pg returns a -1 size, using the pg_size attribute.
>
> 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).

--
Peter Eisentraut peter_e(at)gmx(dot)net http://yi.org/peter-e/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fork 2001-03-05 22:50:50 Re: Re: RPMs for PHP accessing PostgreSQL via ODBC over RedHat
Previous Message Geoff Russell 2001-03-05 22:27:51 Ouch. Inheritance hurts