
Hi all,

I have a problem with metadata.........just read this .......

Let us simply suppose a table "test" with 2 fileds "name (varchar(10))" and 
"age (numeric)" and there b values as name="abc",age="20".

Now in a function i need to develop a list where the column header info has 
to b made in this format i.e., as "column name, column type, column 
width".........

am getting the column name using PQfname function, column type using PQftype 
and column size using PQfsize....... am also able to get each filed values n 
their size correctly..........

but the problem now is ......when i use PQfsize to get the column header size 
then i get a -1 if the field is a variable length in nature else i get the 
exact size........i.e., in the above declared table for both the name and age 
being variable fields am getting -1 for their size.......now i need some 
mechanism to get 10 for "name" header and number of bytes allocated for 
"age"(30,6).......is their any way to overcome this problem? 

Is this a draw back in Postgre? Is there any way i can get the exact size 
that i allocated when creating the table.....infact most of the other 
databases do provide APIs with not having this problem........can anyone help 
me, please.........

Shra


Sat, 27 Apr 2002 00:59:55 +0530
Shra <shravan@yaskatech.com>
None
Shra <shravan@yaskatech.com> writes:
> [ where to get declared-length info for var-length columns ]

This is encoded in the atttypmod field (see PQfmod).  I'd recommend
using format_type() to decode the info, but if you don't mind possibly
having to change your code from time to time, you could just wire
knowledge of the interpretation of typmod into your code.

In future, kindly be more selective about the lists you cross-post to.
I generally make a practice of ignoring questions posted to the bugs
list, for example.

			regards, tom lane

Sat, 27 Apr 2002 11:07:28 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: [BUGS] 
Hi tom,

how to decode the atttypmod field........when i allocate 10 it shows it as 14 
n for 20 it shows it as 24.......my problem is not just with 
varchar........it is for all fields that has variable length .........the 
same atttypmod returns -1 for integer? am confused........

I want the size allocated for each field i a table whether its a var-length 
or fixed length........

Shra

On Saturday 27 April 2002 20:37, you wrote:
> Shra <shravan@yaskatech.com> writes:
> > [ where to get declared-length info for var-length columns ]
>
> This is encoded in the atttypmod field (see PQfmod).  I'd recommend
> using format_type() to decode the info, but if you don't mind possibly
> having to change your code from time to time, you could just wire
> knowledge of the interpretation of typmod into your code.
>
> In future, kindly be more selective about the lists you cross-post to.
> I generally make a practice of ignoring questions posted to the bugs
> list, for example.
>
> 			regards, tom lane

-- 
Shra


Mon, 29 Apr 2002 11:50:25 +0530
Shra <shravan@yaskatech.com>
MetaData (size of datatype)
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..........

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 .........

any better way , please.........

Shra


Mon, 29 Apr 2002 16:46:34 +0530
Shra <shravan@yaskatech.com>
Re: MetaData (size of datatype)
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


29 Apr 2002 15:54:01 +0200
Hannu Krosing <hannu@tm.ee>
Re: MetaData (size of datatype)
Shra <shravan@yaskatech.com> writes:
> 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 .........

The interpretation of typmod is datatype-specific.  That's why I
recommended using format_type.  But if you want to know what format_type
knows, look at the source code (src/backend/utils/adt/format_type.c).

			regards, tom lane

Mon, 29 Apr 2002 10:39:34 -0400
Tom Lane <tgl@sss.pgh.pa.us>
Re: MetaData (size of datatype) 