diff options
Diffstat (limited to 'src/backend/parser/parse_target.c')
-rw-r--r-- | src/backend/parser/parse_target.c | 50 |
1 files changed, 15 insertions, 35 deletions
diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 27e818dcbe2..dd2c0b4e31c 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.135 2005/06/04 19:19:42 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.136 2005/06/05 00:38:10 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -750,52 +750,32 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref) * ExpandAllTables() * Turns '*' (in the target list) into a list of targetlist entries. * - * 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.) + * tlist entries are generated for each relation appearing in the query's + * varnamespace. We do not consider relnamespace because that would include + * input tables of aliasless JOINs, NEW/OLD pseudo-entries, implicit RTEs, + * etc. */ static List * ExpandAllTables(ParseState *pstate) { List *target = NIL; - bool found_table = false; - ListCell *ns; - - foreach(ns, pstate->p_namespace) - { - Node *n = (Node *) lfirst(ns); - int rtindex; - RangeTblEntry *rte; + ListCell *l; - if (IsA(n, RangeTblRef)) - rtindex = ((RangeTblRef *) n)->rtindex; - else if (IsA(n, JoinExpr)) - rtindex = ((JoinExpr *) n)->rtindex; - else - { - elog(ERROR, "unrecognized node type: %d", (int) nodeTag(n)); - rtindex = 0; /* keep compiler quiet */ - } + /* Check for SELECT *; */ + if (!pstate->p_varnamespace) + ereport(ERROR, + (errcode(ERRCODE_SYNTAX_ERROR), + errmsg("SELECT * with no tables specified is not valid"))); - /* - * Ignore added-on relations that were not listed in the FROM - * clause. - */ - rte = rt_fetch(rtindex, pstate->p_rtable); - if (!rte->inFromCl) - continue; + foreach(l, pstate->p_varnamespace) + { + RangeTblEntry *rte = (RangeTblEntry *) lfirst(l); + int rtindex = RTERangeTablePosn(pstate, rte, NULL); - found_table = true; target = list_concat(target, expandRelAttrs(pstate, rte, rtindex, 0)); } - /* Check for SELECT *; */ - if (!found_table) - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("SELECT * with no tables specified is not valid"))); - return target; } |