Re: Calling function from VFP changes character field to Memo

From: Frank Cazabon <frank(dot)cazabon(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Calling function from VFP changes character field to Memo
Date: 2022-11-15 19:10:47
Message-ID: ee0ec151-3f0d-8eef-5dfb-ae47d1a0c695@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 15/11/2022 2:58 pm, Adrian Klaver wrote:
> On 11/15/22 10:54 AM, Frank Cazabon wrote:
>>
>> On 15/11/2022 2:44 pm, Tom Lane wrote:
>>> Frank Cazabon <frank(dot)cazabon(at)gmail(dot)com> writes:
>>>> If however I have a function defined like this
>>>> CREATE OR REPLACE FUNCTION public.testfunction(
>>>>       )
>>>>       RETURNS TABLE
>>>>       (
>>>>           Firstname character(30)
>>>>       )
>>>>       LANGUAGE 'plpgsql'
>>>> AS $BODY$
>>>> BEGIN
>>>>       RETURN QUERY SELECT p.cFirstName FROM patients p;
>>>> END;
>>>> $BODY$;
>>>> And I call:
>>>> SELECT * FROM public.testFunction();
>>>> Then FirstName returns as a Memo field (similar to a Text field).
>>> This is mostly about whatever software stack you're using on the
>>> client side --- Memo is certainly not something Postgres knows about.
>>>
>>>> Any idea what I need to do to get it to return the character(30) type?
>>> There's no chance of getting back the "30" part with this structure,
>>> because function signatures do not carry length restrictions.
>>> What I expect is happening is that you get firstname as an
>>> unspecified-length "character" type, and something on the client
>>> side is deciding to cope with that by calling it "Memo" instead.
>>>
>>> You could perhaps work around that by defining a named composite
>>> type:
>>>
>>> create type testfunction_result as (firstname character(30), ...);
>>>
>>> create function testfunction() returns setof testfunction_result as ...
>>>
>>>             regards, tom lane
>> Thanks, so I could define the function like this - removed the (30):
>>
>> CREATE OR REPLACE FUNCTION public.testfunction(
>>       )
>>       RETURNS TABLE
>>       (
>>           Firstname character
>>       )
>>       LANGUAGE 'plpgsql'
>
> No you don't want to do that:
>
> select 'test'::char;
>  bpchar
> --------
>  t
>
> vs
>
> select 'test'::varchar;
>  varchar
> ---------
>  test
>
> Besides you missed the important part, after creating the type
> testfunction_result:
>
> create function testfunction() returns setof testfunction_result as ...
>

Sorry about the confusion, I have got it working using the type definition.

Thanks for the help

>
>>
>> I'll try the type definition and see if that helps.
>>
>>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Preston Hagar 2022-11-15 19:55:42 Toast Tables, pg_repack, and AWS RDS
Previous Message Frank Cazabon 2022-11-15 19:07:16 Re: Calling function from VFP changes character field to Memo