Re: pl/pgsql, cursors and C function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tomasz Myrta <jasiek(at)klaster(dot)net>
Cc: Lista dyskusyjna pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: pl/pgsql, cursors and C function
Date: 2003-09-23 15:15:09
Message-ID: 16949.1064330109@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tomasz Myrta <jasiek(at)klaster(dot)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;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jeff Kowalczyk 2003-09-23 16:15:53 updating a field with a SUM from another table
Previous Message Montervino, Mariano 2003-09-23 14:56:26 Especial delimiters caracter