From: | Limin Liu <limin(at)pumpkinnet(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org, mpm(at)norwottuck(dot)com |
Subject: | Re: Daily Digest V1 #377 |
Date: | 2001-03-06 00:08:42 |
Message-ID: | 3AA42A8A.8D5954BD@pumpkinnet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>
> 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()?
>
Try this SQL (replace the 'table_name' and 'attribute_name'). This should give you the length of your varchar().
SELECT a.atttypmod-4 as length
FROM pg_class c, pg_attribute a, pg_type t
WHERE c.relname = 'table_name'
AND a.attname = 'attribute_name'
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid;
LM.Liu
From | Date | Subject | |
---|---|---|---|
Next Message | Michelle Murrain | 2001-03-06 00:24:30 | Re: Getting lengths of variable fields |
Previous Message | Tom Lane | 2001-03-06 00:05:15 | Re: Getting lengths of variable fields |