mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Tweak findTargetlistEntry so that bare names occurring in GROUP BY clauses
are sought first as local FROM columns, then as local SELECT-list aliases, and finally as outer FROM columns; the former behavior made outer FROM columns take precedence over aliases. This does not change spec conformance because SQL99 allows only the first case anyway, and it seems more useful and self-consistent. Per gripe from Dennis Bjorklund 2004-04-05.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.127 2004/01/23 02:13:12 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.128 2004/04/18 18:12:57 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1140,10 +1140,18 @@ findTargetlistEntry(ParseState *pstate, Node *node, List *tlist, int clause)
|
||||
* is a matching column. If so, fall through to let
|
||||
* transformExpr() do the rest. NOTE: if name could refer
|
||||
* ambiguously to more than one column name exposed by FROM,
|
||||
* colnameToVar will ereport(ERROR). That's just what we want
|
||||
* colNameToVar will ereport(ERROR). That's just what we want
|
||||
* here.
|
||||
*
|
||||
* Small tweak for 7.4.3: ignore matches in upper query levels.
|
||||
* This effectively changes the search order for bare names to
|
||||
* (1) local FROM variables, (2) local targetlist aliases,
|
||||
* (3) outer FROM variables, whereas before it was (1) (3) (2).
|
||||
* SQL92 and SQL99 do not allow GROUPing BY an outer reference,
|
||||
* so this breaks no cases that are legal per spec, and it
|
||||
* seems a more self-consistent behavior.
|
||||
*/
|
||||
if (colnameToVar(pstate, name) != NULL)
|
||||
if (colNameToVar(pstate, name, true) != NULL)
|
||||
name = NULL;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user