Re: Accessing original TupleDesc from SRF - Mailing list pgsql-hackers

From Joe Conway
Subject Re: Accessing original TupleDesc from SRF
Date
Msg-id 3D710D33.4080605@joeconway.com
Whole thread Raw
In response to Accessing original TupleDesc from SRF  (John Gray <jgray@azuli.co.uk>)
Responses Re: Accessing original TupleDesc from SRF  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
> Joe Conway <mail@joeconway.com> writes:
>>Attached adds:
>>   + TupleDesc queryDesc; /* descriptor for planned query */
>>to ReturnSetInfo, and populates ReturnSetInfo for every function call to
>>  ExecMakeTableFunctionResult, not just when fn_retset.
>
> I thought "expectedDesc" was a more sensible choice of name, so I made
> it that.  Otherwise, patch applied.


I was trying to actually use this new feature today, and ran into a
little bug in nodeFunctionscan.c that prevented it from actually working.

For anonymous composite types, ExecInitFunctionScan builds the tuple
description using:
   tupdesc = BuildDescForRelation(coldeflist);

But BuildDescForRelation leaves initializes the tupdesc like this:
   desc = CreateTemplateTupleDesc(natts, UNDEFOID);

The UNDEFOID later causes an assertion failure in heap_formtuple when
you try to use the tupdesc to build a tuple.

Attached is a very small patch to fix.

>>I haven't done it yet, but I suppose this should be documented in
>>xfunc.sgml.
> Actually, most of what's in src/backend/utils/fmgr/README should be
> transposed into xfunc.sgml someday.

After beta starts I'll work on migrating this to the sgml docs.

Joe

Index: src/backend/executor/nodeFunctionscan.c
===================================================================
RCS file: /opt/src/cvs/pgsql-server/src/backend/executor/nodeFunctionscan.c,v
retrieving revision 1.9
diff -c -r1.9 nodeFunctionscan.c
*** src/backend/executor/nodeFunctionscan.c    30 Aug 2002 23:59:46 -0000    1.9
--- src/backend/executor/nodeFunctionscan.c    31 Aug 2002 18:01:48 -0000
***************
*** 226,231 ****
--- 226,232 ----
          List *coldeflist = rte->coldeflist;

          tupdesc = BuildDescForRelation(coldeflist);
+         tupdesc->tdhasoid = WITHOUTOID;
      }
      else
          elog(ERROR, "Unknown kind of return type specified for function");

pgsql-hackers by date:

Previous
From: "Iavor Raytchev"
Date:
Subject: pgaccess 0.98.8 beta 1 - the show starts
Next
From: Bruce Momjian
Date:
Subject: Re: source code indexer