From: Vegard Bønes <vegard.bones@met.no>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5883: Error when mixing SPI_returntuple with returning regular HeapTuple
Date: Tue, 15 Feb 2011 07:43:04 +0000 (UTC)
Message-ID: <87288500.70191.1297755784580.JavaMail.root@imap1b> (raw)
In-Reply-To: <25635.1297701547@sss.pgh.pa.us>
Ok, I tried to modify the example functions get_data_alternative_a() and get_data_alternative_b(), so that they start with SPI_connect, and end with SPI_finish. Also I removed SPI_connect and SPI_finish from the main function. As I understand you, that should have solved the problem. The result, however, is exactly the same as before.
Please keep in mind that I can call either alternative a or alternative b as many times as I wish during the same sql function call, but I can not mix them.
VG
----- Original Message -----
Fra: "Tom Lane" <tgl@sss.pgh.pa.us>
Til: "vegard bones" <vegard.bones@met.no>
Kopi: pgsql-bugs@postgresql.org
Sendt: 14. februar 2011 17:39:07
Emne: Re: [BUGS] BUG #5883: Error when mixing SPI_returntuple with returning regular HeapTuple
"" <vegard.bones@met.no> writes:
> When creating a server-side C function, things go wrong when I (in the same
> function) return some results via SPI_returntuple, and other results by
> manually creating HeapTuples. This applies even if the source for both
> returns are the same data in the same table.
I think the part of this example that doesn't work is returning from the
function without having exited your SPI context. If you need to produce
multiple rows from a single SPI query, the best solution is to collect
them all during a single call and return them in a tuplestore. You can
*not* return without having called SPI_finish to balance your
SPI_connect.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: vegard.bones@met.no, tgl@sss.pgh.pa.us
Subject: Re: BUG #5883: Error when mixing SPI_returntuple with returning regular HeapTuple
In-Reply-To: <87288500.70191.1297755784580.JavaMail.root@imap1b>
References: <25635.1297701547@sss.pgh.pa.us> <87288500.70191.1297755784580.JavaMail.root@imap1b>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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