aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_target.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-02-14 21:35:07 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-02-14 21:35:07 +0000
commit4a66f9dd54694eb4d7ecce2c7e0f0c50dfde88cd (patch)
tree8810441569d5cf2e29f2a5c2b67ceb91d74deb2d /src/backend/parser/parse_target.c
parentd42d31e78e2f9db73edb0b0ed35cafb1c409bdbf (diff)
downloadpostgresql-4a66f9dd54694eb4d7ecce2c7e0f0c50dfde88cd.tar.gz
postgresql-4a66f9dd54694eb4d7ecce2c7e0f0c50dfde88cd.zip
Change scoping of table and join refnames to conform to SQL92: a JOIN
clause with an alias is a <subquery> and therefore hides table references appearing within it, according to the spec. This is the same as the preliminary patch I posted to pgsql-patches yesterday, plus some really grotty code in ruleutils.c to reverse-list a query tree with the correct alias name depending on context. I'd rather not have done that, but unless we want to force another initdb for 7.1, there's no other way for now.
Diffstat (limited to 'src/backend/parser/parse_target.c')
-rw-r--r--src/backend/parser/parse_target.c53
1 files changed, 31 insertions, 22 deletions
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c
index 647b176f059..6b566da7475 100644
--- a/src/backend/parser/parse_target.c
+++ b/src/backend/parser/parse_target.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.64 2001/01/24 19:43:02 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.65 2001/02/14 21:35:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -212,29 +212,37 @@ updateTargetListEntry(ParseState *pstate,
*/
if (indirection)
{
- Attr *att = makeAttr(pstrdup(RelationGetRelationName(rd)),
- colname);
Node *arrayBase;
ArrayRef *aref;
- arrayBase = ParseNestedFuncOrColumn(pstate, att, EXPR_COLUMN_FIRST);
- aref = transformArraySubscripts(pstate, arrayBase,
- indirection,
- pstate->p_is_insert,
- tle->expr);
if (pstate->p_is_insert)
{
-
/*
* The command is INSERT INTO table (arraycol[subscripts]) ...
* so there is not really a source array value to work with.
* Let the executor do something reasonable, if it can. Notice
- * that we forced transformArraySubscripts to treat the
- * subscripting op as an array-slice op above, so the source
- * data will have been coerced to array type.
+ * that we force transformArraySubscripts to treat the
+ * subscripting op as an array-slice op below, so the source
+ * data will have been coerced to the array type.
+ */
+ arrayBase = NULL; /* signal there is no source array */
+ }
+ else
+ {
+ /*
+ * Build a Var for the array to be updated.
*/
- aref->refexpr = NULL; /* signal there is no source array */
+ arrayBase = (Node *) make_var(pstate,
+ pstate->p_target_rangetblentry,
+ attrno);
}
+
+ aref = transformArraySubscripts(pstate,
+ arrayBase,
+ attrtype,
+ indirection,
+ pstate->p_is_insert,
+ tle->expr);
tle->expr = (Node *) aref;
}
else
@@ -385,22 +393,19 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
/* ExpandAllTables()
* Turns '*' (in the target list) into a list of targetlist entries.
*
- * tlist entries are generated for each relation appearing in the FROM list,
- * which by now has been transformed into a joinlist.
+ * tlist entries are generated for each relation appearing at the top level
+ * of the query's namespace, except for RTEs marked not inFromCl. (These
+ * may include NEW/OLD pseudo-entries, implicit RTEs, etc.)
*/
static List *
ExpandAllTables(ParseState *pstate)
{
List *target = NIL;
- List *jt;
+ List *ns;
- /* SELECT *; */
- if (pstate->p_joinlist == NIL)
- elog(ERROR, "Wildcard with no tables specified not allowed");
-
- foreach(jt, pstate->p_joinlist)
+ foreach(ns, pstate->p_namespace)
{
- Node *n = (Node *) lfirst(jt);
+ Node *n = (Node *) lfirst(ns);
if (IsA(n, RangeTblRef))
{
@@ -431,6 +436,10 @@ ExpandAllTables(ParseState *pstate)
"\n\t%s", nodeToString(n));
}
+ /* Check for SELECT *; */
+ if (target == NIL)
+ elog(ERROR, "Wildcard with no tables specified not allowed");
+
return target;
}