Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 1CE7D1337B4F for ; Mon, 14 Feb 2011 12:39:31 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 24432-08 for ; Mon, 14 Feb 2011 16:39:20 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id C6A711337999 for ; Mon, 14 Feb 2011 12:39:19 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p1EGd7N9025636; Mon, 14 Feb 2011 11:39:08 -0500 (EST) To: "" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #5883: Error when mixing SPI_returntuple with returning regular HeapTuple In-reply-to: <201102141140.p1EBeeG8060816@wwwmaster.postgresql.org> References: <201102141140.p1EBeeG8060816@wwwmaster.postgresql.org> Comments: In-reply-to "" message dated "Mon, 14 Feb 2011 11:40:40 +0000" Date: Mon, 14 Feb 2011 11:39:07 -0500 Message-ID: <25635.1297701547@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/126 X-Sequence-Number: 29398 "" 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