pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedc-function returning multiple rows
2+ messages / 2 participants
[nested] [flat]
* c-function returning multiple rows
@ 2001-04-24 15:55 Alexey Nalbat <alexey@price.ru>
0 siblings, 1 reply; 2+ messages in thread
From: Alexey Nalbat @ 2001-04-24 15:55 UTC (permalink / raw)
To: pgsql-bugs@postgresql.org
Hello, I encountered the following problem ( at PostgreSQL 7.1 on Solaris i386 )
with compiling c-function returning multiple rows. Here is a transcript.
+++
+++
postgres@beta:~$ cd lib/
postgres@beta:~/lib$ cat <<! >myrand.c
> #include <stdlib.h>
> #include "postgres.h"
> #include "fmgr.h"
> #include "nodes/execnodes.h"
>
> PG_FUNCTION_INFO_V1(myrand);
>
> Datum
> myrand(PG_FUNCTION_ARGS)
> {
> if ( 100*rand() > RAND_MAX )
> {
> fcinfo->resultinfo->isDone = ExprMultipleResult;
> PG_RETURN_INT32( PG_GETARG_INT32(0)*rand()/RAND_MAX );
> }
> else
> {
> fcinfo->resultinfo->isDone = ExprEndResult;
> PG_RETURN_NULL();
> }
> }
> !
postgres@beta:~/lib$ gcc -I /usr/local/include/pgsql -fpic -c myrand.c
myrand.c: In function `triple':
myrand.c:13: structure has no member named `isDone'
myrand.c:18: structure has no member named `isDone'
+++
+++
I digged into sources and supposed that line 61 in fmgr.h might be 'struct ReturnSetInfo *resultinfo;'
instead of 'struct Node *resultinfo;'. But I'm not sure if it is correct.
After changing this line in file fmgr.h it became working. Here is a transcript.
+++
+++
postgres@beta:~/lib$ gcc -I /usr/local/include/pgsql -fpic -c myrand.c
postgres@beta:~/lib$ gcc -G -o myrand.so myrand.o
postgres@beta:~/lib$ psql
Welcome to psql, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit
postgres=# CREATE FUNCTION myrand(int4) RETURNS SETOF int4 AS '/var/local/lib/pgsql/lib/myrand.so' LANGUAGE 'C';
CREATE
postgres=# SELECT myrand(50);
?column?
----------
26
46
30
29
40
8
22
38
23
18
2
43
24
44
22
46
48
15
(18 rows)
+++
+++
--
WBR, Alexey Nalbat
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: c-function returning multiple rows
@ 2001-04-26 14:55 Tom Lane <tgl@sss.pgh.pa.us>
parent: Alexey Nalbat <alexey@price.ru>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2001-04-26 14:55 UTC (permalink / raw)
To: alexey@price.ru; +Cc: pgsql-bugs@postgresql.org
Alexey Nalbat <alexey@price.ru> writes:
> I digged into sources and supposed that line 61 in fmgr.h might be
> 'struct ReturnSetInfo *resultinfo;' instead of 'struct Node
> *resultinfo;'. But I'm not sure if it is correct.
No, it isn't. fmgr.h is correct as given, because the resultinfo
field might point at various different kinds of Nodes. You need to
do an IsA test and then a cast, instead. See the code in
src/backend/executor/functions.c for an example.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-04-26 14:55 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-24 15:55 c-function returning multiple rows Alexey Nalbat <alexey@price.ru>
2001-04-26 14:55 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox