Re: MetaData (size of datatype) - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: MetaData (size of datatype)
Date
Msg-id 1020088441.27494.10.camel@taru.tm.ee
Whole thread Raw
In response to Re: MetaData (size of datatype)  (Shra <shravan@yaskatech.com>)
List pgsql-hackers
On Mon, 2002-04-29 at 13:16, Shra wrote:
> Hi Hannu,
> 
> > -1 is given for types that are of fixed size and whose length can be
> > read from pg_type.typlen for that type.
> 
> I don't think so...jsut look into this file pq_type.h.... it says.........
> *****************************************************************
>  typlen is the number of bytes we use to represent a value of this type, e.g. 
> 4 for an int4.  But for a variable length type, typlen is -1
> *****************************************************************
> 
> -1 is for variable length n not for fixed length.........this point is very 
> clear even in documentation..........

Yes, it in pg_type.typlen it is -1 is for variable length and actual
length for fixed-length types

in pg_attribute.attypmod it is -1 for _fixed_ length types and actual
length for variable length types (actual length = defined length + 4
bytes of length bytes)

> now how to find length for a numeric, varchar or anyother one that has 
> variable length where the system PQfsize returns -1.........?
> 
> As tom said.....The type is encoded in the atttypmod field (see PQfmod) and 
> recommended using format_type().....
> but when this is used, it returns -1 for integer , real n other fixed 
> datatypes .........

so do as Tom said - 

if   PQfsize returns -1
then   use  PQfmod
else   use PQfsize

-----------
Hannu



pgsql-hackers by date:

Previous
From: Shra
Date:
Subject: Re: MetaData (size of datatype)
Next
From: Shad
Date:
Subject: Re: PSQL \x \l command issues