aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execQual.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-06-11 22:22:42 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-06-11 22:22:42 +0000
commita9545b3aef0d41fdb84bc6a30fa2e563020acad2 (patch)
tree4b6f9353cf6846a6b1ce2b96ddbf2ffbf2a42d58 /src/backend/executor/execQual.c
parentbdc71c2cb162297f7f69d8d2be113c2689f5bd6e (diff)
downloadpostgresql-a9545b3aef0d41fdb84bc6a30fa2e563020acad2.tar.gz
postgresql-a9545b3aef0d41fdb84bc6a30fa2e563020acad2.zip
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.
Diffstat (limited to 'src/backend/executor/execQual.c')
-rw-r--r--src/backend/executor/execQual.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c
index 5549142e703..69d28e78a4b 100644
--- a/src/backend/executor/execQual.c
+++ b/src/backend/executor/execQual.c
@@ -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");
-
- if (execCurrentOf(cexpr->cursor_name, tup->t_tableOid, &cursor_tid))
- result = ItemPointerEquals(&cursor_tid, &(tup->t_self));
+ /* 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, econtext, tableoid, &cursor_tid))
+ result = ItemPointerEquals(&cursor_tid, tuple_tid);
else
result = false;