Skip site navigation (1) Skip section navigation (2)

Re: c-function returns multiple rows

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Kirill Krasnosselov <kirill(at)digicol(dot)de>,pgsql-novice(at)postgresql(dot)org
Subject: Re: c-function returns multiple rows
Date: 2003-08-23 21:36:09
Message-ID: 3F47DE49.7040201@joeconway.com (view raw or flat)
Thread:
Lists: 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


In response to

pgsql-novice by date

Next:From: Hans JorgensenDate: 2003-08-24 10:13:05
Subject: Porting from MSSQL Server
Previous:From: Tomka GergelyDate: 2003-08-23 16:58:25
Subject: Re: dump with nice comments

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group