1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

Improve UPDATE/DELETE WHERE CURRENT OF so that they can be used from plpgsql

with a plpgsql-defined cursor.  The underlying mechanism for this is that the
main SQL engine will now take "WHERE CURRENT OF $n" where $n is a refcursor
parameter.  Not sure if we should document that fact or consider it an
implementation detail.  Per discussion with Pavel Stehule.
This commit is contained in:
Tom Lane
2007-06-11 22:22:42 +00:00
parent bdc71c2cb1
commit a9545b3aef
13 changed files with 225 additions and 72 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.219 2007/06/11 01:16:22 tgl Exp $
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.220 2007/06/11 22:22:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -3632,8 +3632,10 @@ ExecEvalCurrentOfExpr(ExprState *exprstate, ExprContext *econtext,
bool *isNull, ExprDoneCond *isDone)
{
CurrentOfExpr *cexpr = (CurrentOfExpr *) exprstate->expr;
bool result;
HeapTuple tup;
bool result;
bool lisnull;
Oid tableoid;
ItemPointer tuple_tid;
ItemPointerData cursor_tid;
if (isDone)
@ -3643,12 +3645,19 @@ ExecEvalCurrentOfExpr(ExprState *exprstate, ExprContext *econtext,
Assert(cexpr->cvarno != INNER);
Assert(cexpr->cvarno != OUTER);
Assert(!TupIsNull(econtext->ecxt_scantuple));
tup = econtext->ecxt_scantuple->tts_tuple;
if (tup == NULL)
elog(ERROR, "CURRENT OF applied to non-materialized tuple");
/* Use slot_getattr to catch any possible mistakes */
tableoid = DatumGetObjectId(slot_getattr(econtext->ecxt_scantuple,
TableOidAttributeNumber,
&lisnull));
Assert(!lisnull);
tuple_tid = (ItemPointer)
DatumGetPointer(slot_getattr(econtext->ecxt_scantuple,
SelfItemPointerAttributeNumber,
&lisnull));
Assert(!lisnull);
if (execCurrentOf(cexpr->cursor_name, tup->t_tableOid, &cursor_tid))
result = ItemPointerEquals(&cursor_tid, &(tup->t_self));
if (execCurrentOf(cexpr, econtext, tableoid, &cursor_tid))
result = ItemPointerEquals(&cursor_tid, tuple_tid);
else
result = false;