X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 65766D1BA5B for ; Tue, 23 Sep 2003 15:15:52 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 07654-09 for ; Tue, 23 Sep 2003 12:15:20 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 02A33D1B8EC for ; Tue, 23 Sep 2003 12:15:20 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id h8NFF9iP016950; Tue, 23 Sep 2003 11:15:09 -0400 (EDT) To: Tomasz Myrta Cc: Lista dyskusyjna pgsql-sql Subject: Re: pl/pgsql, cursors and C function In-reply-to: <3F70314C.30507@klaster.net> References: <3F70314C.30507@klaster.net> Comments: In-reply-to Tomasz Myrta message dated "Tue, 23 Sep 2003 13:41:00 +0200" Date: Tue, 23 Sep 2003 11:15:09 -0400 Message-ID: <16949.1064330109@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/271 X-Sequence-Number: 15249 Tomasz Myrta writes: > I don't understand ERROR message at all: > ERROR: SPI_prepare() failed on "SELECT $1 " This is a bug. Or two bugs, actually: one of yours and one of PG's. I have repaired the PG bug with the attached patch. The bug in your code is that your C function needs to call SPI_connect and SPI_finish if it's going to use any SPI operations. regards, tom lane Index: spi.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/executor/spi.c,v retrieving revision 1.75.2.3 diff -c -r1.75.2.3 spi.c *** spi.c 14 Feb 2003 21:12:54 -0000 1.75.2.3 --- spi.c 23 Sep 2003 15:09:39 -0000 *************** *** 1387,1393 **** elog(ERROR, "invalid portal in SPI cursor operation"); /* Push the SPI stack */ ! _SPI_begin_call(true); /* Reset the SPI result */ SPI_processed = 0; --- 1387,1394 ---- elog(ERROR, "invalid portal in SPI cursor operation"); /* Push the SPI stack */ ! if (_SPI_begin_call(true) < 0) ! elog(ERROR, "SPI cursor operation called while not connected"); /* Reset the SPI result */ SPI_processed = 0;