summaryrefslogtreecommitdiff
path: root/src/backend/parser/analyze.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-01-11 19:03:15 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2014-01-11 19:03:15 -0500
commit27ff4cfe760a79c78eac2948cea67f2ae486cbbf (patch)
treef47dc4f947ed95b08bb0c1bdb8f5bdd2e16ed8b3 /src/backend/parser/analyze.c
parent5bfcc9ec5e78733c5770c17d43c0315e0fcc14b9 (diff)
Disallow LATERAL references to the target table of an UPDATE/DELETE.
On second thought, commit 0c051c90082da0b7e5bcaf9aabcbd4f361137cdc 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.
Diffstat (limited to 'src/backend/parser/analyze.c')
-rw-r--r--src/backend/parser/analyze.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 2d8dc57d690..7c31b9d65e8 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -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);