Re: return can contains any row or record functions - Mailing list pgsql-patches

From Neil Conway
Subject Re: return can contains any row or record functions
Date
Msg-id 1131405013.6884.129.camel@localhost.localdomain
Whole thread Raw
In response to return can contains any row or record functions  ("Pavel Stehule" <pavel.stehule@hotmail.com>)
Responses Re: return can contains any row or record functions
List pgsql-patches
I'm confused by this part of the patch, circa line 1835 of pl_exec.c:

/* coerce type if needed */
if (estate->rsi && IsA(estate->rsi, ReturnSetInfo) &&
    estate->rsi->expectedDesc != NULL &&
    !compatible_tupdesc(estate->rsi->expectedDesc, in_tupdesc))
{
    estate->retval = (Datum) make_tuple_from_tuple(estate,
                                                   &td,
                                                   in_tupdesc,
                    estate->rsi->expectedDesc);
    if (estate->retval == PointerGetDatum(NULL))
    ereport(...);

    estate->rettupdesc = estate->rsi->expectedDesc;
}
else
{
    estate->retval = (Datum) heap_copytuple(&td);
    estate->rettupdesc = in_tupdesc;
}

This is for the "tuple returning function" case of RETURN. estate->rsi
seems to contain information for set-returning functions -- why do we
need to use it to obtain the expected tupledesc of the function's return
value? I'm just wondering if we ought to be fetching this from somewhere
else.

As it stands, this seems plainly wrong:

create type __trt as (x integer, y integer, z text);

create or replace function return_row4() returns __trt as $$
begin
  return (1,2,'3'::text,4);
end;
$$ language plpgsql;

select return_row4();
 return_row4
-------------
 (1,2,3,4)
(1 row)

-Neil



pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: return can contains any row or record functions
Next
From: "Pavel Stehule"
Date:
Subject: Re: return can contains any row or record functions