Re: [GENERAL] strange error when inserting via a SRF into a table with a foreign key constraint

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [GENERAL] strange error when inserting via a SRF into a table with a foreign key constraint
Date: 2006-10-11 22:24:31
Message-ID: 28992.1160605471@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

"Merlin Moncure" <mmoncure(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Tassonis 2006-10-11 22:27:26 Re: more anti-postgresql FUD
Previous Message Richard Broersma Jr 2006-10-11 21:43:39 Re: strange error when inserting via a SRF into a table with a foreign key constraint

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2006-10-11 22:25:05 Re: [COMMITTERS] pgsql: Repair incorrect check for coercion
Previous Message Bruce Momjian 2006-10-11 22:22:25 Re: hstore isexists