Re: pl/pgsql, cursors and C function - Mailing list pgsql-sql

From Tom Lane
Subject Re: pl/pgsql, cursors and C function
Date
Msg-id 16949.1064330109@sss.pgh.pa.us
Whole thread Raw
In response to pl/pgsql, cursors and C function  (Tomasz Myrta <jasiek@klaster.net>)
Responses Re: pl/pgsql, cursors and C function  (Tomasz Myrta <jasiek@klaster.net>)
List pgsql-sql
Tomasz Myrta <jasiek@klaster.net> 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;
 


pgsql-sql by date:

Previous
From: Tomasz Myrta
Date:
Subject: pl/pgsql, cursors and C function
Next
From: Jeff Kowalczyk
Date:
Subject: updating a field with a SUM from another table