Re: Libpq: PQftype, PQfsize - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Libpq: PQftype, PQfsize
Date
Msg-id 13440.1281622557@sss.pgh.pa.us
Whole thread Raw
In response to Re: Libpq: PQftype, PQfsize  ("Bozena Potempa" <Bozena.Potempa@otc.pl>)
Responses Re: Libpq: PQftype, PQfsize
List pgsql-hackers
"Bozena Potempa" <Bozena.Potempa@otc.pl> writes:
> Thank you. In this case (substring) there is no much to predict, just a
> simple calculation, but I understand that it is a part of larger and more
> complicated functionality. I tried to find a workaround with a type cast: 
> select substr(fc,1,2)::varchar(2) from test
> Now the type returned is varchar, but the size is still -1. I think that it
> is not a correct return: the size is specified explicitly in the query and
> could be used by PQfsize. 

Oh ... actually the problem there is that you have the wrong idea about
what PQfsize means.  What that returns is pg_type.typlen for the data
type, which is always going to be -1 for a varlena type like varchar.

The thing that you need to look at if you want to see information like
the max length of a varchar is typmod (PQfmod).  The typmod generally
has some funny datatype-specific encoding; for varchar and char it
works like this:-1: max length unknown or unspecifiedn>0: max length is n-4 characters
        regards, tom lane


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: review: psql: edit function, show function commands patch
Next
From: Tom Lane
Date:
Subject: Re: Regression tests versus the buildfarm environment