mirror of
https://github.com/postgres/postgres.git
synced 2025-08-21 10:42:50 +03:00
Disallow LATERAL references to the target table of an UPDATE/DELETE.
On second thought, commit 0c051c9008
was
over-hasty: rather than allowing this case, we ought to reject it for now.
That leaves the field clear for a future feature that allows the target
table to be re-specified in the FROM (or USING) clause, which will enable
left-joining the target table to something else. We can then also allow
LATERAL references to such an explicitly re-specified target table.
But allowing them right now will create ambiguities or worse for such a
feature, and it isn't something we documented 9.3 as supporting.
While at it, add a convenience subroutine to avoid having several copies
of the ereport for disalllowed-LATERAL-reference cases.
This commit is contained in:
@@ -367,8 +367,9 @@ transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
|
||||
/* there's no DISTINCT in DELETE */
|
||||
qry->distinctClause = NIL;
|
||||
|
||||
/* subqueries in USING can see the result relation only via LATERAL */
|
||||
/* subqueries in USING cannot access the result relation */
|
||||
nsitem->p_lateral_only = true;
|
||||
nsitem->p_lateral_ok = false;
|
||||
|
||||
/*
|
||||
* The USING clause is non-standard SQL syntax, and is equivalent in
|
||||
@@ -378,8 +379,9 @@ transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
|
||||
*/
|
||||
transformFromClause(pstate, stmt->usingClause);
|
||||
|
||||
/* remaining clauses can see the result relation normally */
|
||||
/* remaining clauses can reference the result relation normally */
|
||||
nsitem->p_lateral_only = false;
|
||||
nsitem->p_lateral_ok = true;
|
||||
|
||||
qual = transformWhereClause(pstate, stmt->whereClause,
|
||||
EXPR_KIND_WHERE, "WHERE");
|
||||
@@ -1925,8 +1927,9 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
|
||||
/* grab the namespace item made by setTargetTable */
|
||||
nsitem = (ParseNamespaceItem *) llast(pstate->p_namespace);
|
||||
|
||||
/* subqueries in FROM can see the result relation only via LATERAL */
|
||||
/* subqueries in FROM cannot access the result relation */
|
||||
nsitem->p_lateral_only = true;
|
||||
nsitem->p_lateral_ok = false;
|
||||
|
||||
/*
|
||||
* the FROM clause is non-standard SQL syntax. We used to be able to do
|
||||
@@ -1934,8 +1937,9 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
|
||||
*/
|
||||
transformFromClause(pstate, stmt->fromClause);
|
||||
|
||||
/* remaining clauses can see the result relation normally */
|
||||
/* remaining clauses can reference the result relation normally */
|
||||
nsitem->p_lateral_only = false;
|
||||
nsitem->p_lateral_ok = true;
|
||||
|
||||
qry->targetList = transformTargetList(pstate, stmt->targetList,
|
||||
EXPR_KIND_UPDATE_SOURCE);
|
||||
|
Reference in New Issue
Block a user