Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id E853B1337B34 for ; Tue, 15 Feb 2011 03:59:48 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 52948-01 for ; Tue, 15 Feb 2011 07:59:41 +0000 (UTC) X-Greylist: delayed 00:16:34.489704 by SQLgrey-1.7.6 Received: from smtp2.oslo.dnmi.no (smtp2.oslo.dnmi.no [128.39.62.242]) by mail.postgresql.org (Postfix) with ESMTP id CA7C21337B4A for ; Tue, 15 Feb 2011 03:59:40 -0400 (AST) Received: from imap1b.met.no ([157.249.16.99] helo=imap1.met.no) by smtp2.oslo.dnmi.no with esmtp (Exim 4.69) (envelope-from ) id 1PpFYv-0005z9-9J; Tue, 15 Feb 2011 07:43:05 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by imap1.met.no (Postfix) with ESMTP id 376C83CEA11B; Tue, 15 Feb 2011 07:43:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at met.no Received: from imap1.met.no ([127.0.0.1]) by localhost (imap1.met.no [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZpUCaqab80ch; Tue, 15 Feb 2011 07:43:04 +0000 (UTC) Received: from imap1.met.no (imap1.met.no [157.249.16.100]) by imap1.met.no (Postfix) with ESMTP id 9780D3CEA125; Tue, 15 Feb 2011 07:43:04 +0000 (UTC) Date: Tue, 15 Feb 2011 07:43:04 +0000 (UTC) From: =?utf-8?Q?Vegard_B=C3=B8nes?= To: Tom Lane Cc: pgsql-bugs@postgresql.org Message-ID: <87288500.70191.1297755784580.JavaMail.root@imap1b> In-Reply-To: <25635.1297701547@sss.pgh.pa.us> Subject: Re: BUG #5883: Error when mixing SPI_returntuple with returning regular HeapTuple MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [157.249.32.237] X-Mailer: Zimbra 6.0.7_GA_2476.RHEL4 (ZimbraWebClient - FF3.0 (Linux)/6.0.7_GA_2473.UBUNTU8_64) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201102/131 X-Sequence-Number: 29403 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" Til: "vegard bones" 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 "" 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