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

From Bozena Potempa
Subject Re: Libpq: PQftype, PQfsize
Date
Msg-id E1Oj8Sd-0002UT-BJ@ns.otc.pl
Whole thread Raw
In response to Re: Libpq: PQftype, PQfsize  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Libpq: PQftype, PQfsize
List pgsql-hackers
>From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
[..]
>"Bozena Potempa" <Bozena.Potempa@otc.pl> writes:
>> I have a test table with varchar(40) column. After executing the 
>> following
>> query: 
>> select substr(fc,1,2) from test
>> PQftype returns for the result column PG_TYPE_TEXT and 
>PQfsize returns -1. 
>> Is it the expected behaviour?
>
>Yes.  substr() returns text.  But even if it returned varchar, 
>you'd probably get -1 for the fsize.  PG does not make any 
>attempt to predict the result width of functions.

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. 

Bozena



pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: typos in HS source code comment
Next
From: Peter Eisentraut
Date:
Subject: Re: Regression tests versus the buildfarm environment