Re: [GENERAL] strange error when inserting via a SRF into a table with a foreign key constraint - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [GENERAL] strange error when inserting via a SRF into a table with a foreign key constraint
Date
Msg-id 28992.1160605471@sss.pgh.pa.us
Whole thread Raw
List pgsql-hackers
"Merlin Moncure" <mmoncure@gmail.com> writes:
> I got the error mesage,
> ERROR:  could not find relation 19693 among query result relations,

Oooh, that's an interesting one.  The stack trace from the error call
is

#0  errfinish (dummy=0) at elog.c:313
#1  0x356584 in elog_finish (elevel=1073815392,    fmt=0xcc130 "could not find relation %u among query result
relations")  at elog.c:939
 
#2  0x1ef59c in afterTriggerInvokeEvents (events=0x400ec508, firing_id=0,    estate=0x40109be8, delete_ok=1 '\001') at
trigger.c:2331
#3  0x1ef9dc in AfterTriggerEndQuery (estate=0x40109be8) at trigger.c:2556
#4  0x211878 in postquel_end (es=0x40105e18) at functions.c:404
#5  0x211a38 in postquel_execute (es=0x40105e18, fcinfo=0x7b03ba40,    fcache=0x401049b8, resultcontext=0x4007c4e0) at
functions.c:479
#6  0x211c68 in fmgr_sql (fcinfo=0x7b03ba40) at functions.c:639
#7  0x2097b4 in ExecMakeFunctionResult (fcache=0x40104280,    econtext=0x40104108, isNull=0x40104932 "",
isDone=0x401049a0)  at execQual.c:1057
 
...

What the heck is it doing trying to fire triggers from inside the SQL
function, which is merely doing a SELECT?  It looks to me like we need
to rethink where the AfterTriggerBeginQuery and AfterTriggerEndQuery
calls are in functions.c.  I think what is happening is that control
returns from the SQL function after obtaining its first result row,
with the trigger stack still at level one (inside the function), and
so the first AFTER INSERT event gets queued as being something inside
the function.

8.0 has the same bug although the manifestation is different.  Not
sure about 7.4 --- this test case doesn't work for lack of
generate_series.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: hstore isexists
Next
From: Bruce Momjian
Date:
Subject: Re: [COMMITTERS] pgsql: Repair incorrect check for coercion