aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/analyze.c21
-rw-r--r--src/backend/parser/parse_clause.c4
-rw-r--r--src/backend/parser/parse_relation.c4
3 files changed, 29 insertions, 0 deletions
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c
index 60cce378453..6560b86e4b2 100644
--- a/src/backend/parser/analyze.c
+++ b/src/backend/parser/analyze.c
@@ -342,6 +342,7 @@ static Query *
transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
{
Query *qry = makeNode(Query);
+ ParseNamespaceItem *nsitem;
Node *qual;
qry->commandType = CMD_DELETE;
@@ -360,8 +361,15 @@ transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
true,
ACL_DELETE);
+ /* grab the namespace item made by setTargetTable */
+ nsitem = (ParseNamespaceItem *) llast(pstate->p_namespace);
+
+ /* there's no DISTINCT in DELETE */
qry->distinctClause = NIL;
+ /* subqueries in USING can see the result relation only via LATERAL */
+ nsitem->p_lateral_only = true;
+
/*
* The USING clause is non-standard SQL syntax, and is equivalent in
* functionality to the FROM list that can be specified for UPDATE. The
@@ -370,6 +378,9 @@ transformDeleteStmt(ParseState *pstate, DeleteStmt *stmt)
*/
transformFromClause(pstate, stmt->usingClause);
+ /* remaining clauses can see the result relation normally */
+ nsitem->p_lateral_only = false;
+
qual = transformWhereClause(pstate, stmt->whereClause,
EXPR_KIND_WHERE, "WHERE");
@@ -1889,6 +1900,7 @@ static Query *
transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
{
Query *qry = makeNode(Query);
+ ParseNamespaceItem *nsitem;
RangeTblEntry *target_rte;
Node *qual;
ListCell *origTargetList;
@@ -1910,12 +1922,21 @@ transformUpdateStmt(ParseState *pstate, UpdateStmt *stmt)
true,
ACL_UPDATE);
+ /* grab the namespace item made by setTargetTable */
+ nsitem = (ParseNamespaceItem *) llast(pstate->p_namespace);
+
+ /* subqueries in FROM can see the result relation only via LATERAL */
+ nsitem->p_lateral_only = true;
+
/*
* the FROM clause is non-standard SQL syntax. We used to be able to do
* this with REPLACE in POSTQUEL so we keep the feature.
*/
transformFromClause(pstate, stmt->fromClause);
+ /* remaining clauses can see the result relation normally */
+ nsitem->p_lateral_only = false;
+
qry->targetList = transformTargetList(pstate, stmt->targetList,
EXPR_KIND_UPDATE_SOURCE);
diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c
index 05ddb8c3e74..51db595641a 100644
--- a/src/backend/parser/parse_clause.c
+++ b/src/backend/parser/parse_clause.c
@@ -204,6 +204,10 @@ setTargetTable(ParseState *pstate, RangeVar *relation,
/*
* If UPDATE/DELETE, add table to joinlist and namespace.
+ *
+ * Note: some callers know that they can find the new ParseNamespaceItem
+ * at the end of the pstate->p_namespace list. This is a bit ugly but not
+ * worth complicating this function's signature for.
*/
if (alsoSource)
addRTEtoQuery(pstate, rte, true, true, true);
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
index cd8d75e23d9..a7f563b1b14 100644
--- a/src/backend/parser/parse_relation.c
+++ b/src/backend/parser/parse_relation.c
@@ -1730,6 +1730,10 @@ isLockedRefname(ParseState *pstate, const char *refname)
* and/or namespace list. (We assume caller has checked for any
* namespace conflicts.) The RTE is always marked as unconditionally
* visible, that is, not LATERAL-only.
+ *
+ * Note: some callers know that they can find the new ParseNamespaceItem
+ * at the end of the pstate->p_namespace list. This is a bit ugly but not
+ * worth complicating this function's signature for.
*/
void
addRTEtoQuery(ParseState *pstate, RangeTblEntry *rte,