Re: c-function returns multiple rows - Mailing list pgsql-novice

From Joe Conway
Subject Re: c-function returns multiple rows
Date
Msg-id 3F47DE49.7040201@joeconway.com
Whole thread Raw
In response to Re: c-function returns multiple rows  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
Tom Lane wrote:
> This looks like it should work, but you're living dangerously
> by not checking that you're being called the way you expect.
> You should have something like
>
>     if (!fcinfo->resultinfo || !IsA(fcinfo->resultinfo,ReturnSetInfo))
>         elog(ERROR, ...);
>
> in there before trying to dereference the pointer.
>
>>In my opinion this function call shall returns a empty table,
>>but this call does not end.
>

Works here on 7.3.4 (actually 7.3 stable branch after 7.3.4 was released):

extern Datum dc_ftx(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(dc_ftx);
Datum dc_ftx(PG_FUNCTION_ARGS)
{
   ReturnSetInfo* rsi;
   if (!fcinfo->resultinfo || !IsA(fcinfo->resultinfo,ReturnSetInfo))
     elog(ERROR, "called in unsupported context");
   rsi = (ReturnSetInfo *)fcinfo->resultinfo;
   rsi->isDone = ExprEndResult;
   PG_RETURN_NULL();
}

regression=# select version();
                            version

--------------------------------------------------------------------
  PostgreSQL 7.3.4 on i386-redhat-linux-gnu, compiled by GCC
i386-redhat-linux-gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
(1 row)

regression=# select dc_ftx(10);
  dc_ftx
--------
(0 rows)

What do you mean by "call does not end". Does it eventually crash?

Joe


pgsql-novice by date:

Previous
From: Tomka Gergely
Date:
Subject: Re: dump with nice comments
Next
From: "Hans Jorgensen"
Date:
Subject: Porting from MSSQL Server