Re: SPI_connect problems - Mailing list pgsql-interfaces

From Tom Lane
Subject Re: SPI_connect problems
Date
Msg-id 5776.966954748@sss.pgh.pa.us
Whole thread Raw
In response to SPI_connect problems  ("Joonas Makkonen" <joonas.makkonen@infosto.fi>)
List pgsql-interfaces
"Joonas Makkonen" <joonas.makkonen@infosto.fi> writes:
> I have a trigger function written in C that uses SPI to fetch certain data
> from the db. The problem is that about 20% of the time SPI_connect()
> returns:

> NOTICE:  SPI_connect() failed in RI_FKey_check()

> Any ideas what might be causing this?

It looks like you have some referential integrity triggers in your
database that are getting fired during the query you execute from your
SPI call.  The RI triggers also use SPI.  Recursive entry to SPI is
supposed to work, but evidently SPI_connect() isn't happy.  After a
quick look at the code (see src/backend/executor/spi.c) it seems the
only way that could happen is if there's a mismatch of SPI_push and
SPI_pop operations, leaving _SPI_curid pointing at the wrong stack
level.  This might be your error, or it might be a bug in the RI
trigger code or in SPI itself.  I'd suggest tracing through the
SPI operations (use a debugger, or insert printf()s) until you
understand what's happening.

BTW, the RI code is in src/backend/utils/adt/ri_triggers.c
        regards, tom lane


pgsql-interfaces by date:

Previous
From: John Thorhauer
Date:
Subject: odbc blob
Next
From: Gérald de Roany
Date:
Subject: a question of TIME