mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Use variable aliases, if supplied, rather than real column names in
complaints about ungrouped variables. This is for consistency with behavior elsewhere, notably the fact that the relname is reported as an alias in these same complaints. Also, it'll work with subselect- in-FROM where old code didn't.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.47 2000/09/12 21:07:02 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.48 2000/09/25 18:14:54 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -713,6 +713,43 @@ expandNamesVars(ParseState *pstate, List *names, List *vars)
|
||||
return te_list;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* get_rte_attribute_name
|
||||
* Get an attribute name from a RangeTblEntry
|
||||
*
|
||||
* This is unlike get_attname() because we use aliases if available.
|
||||
* In particular, it will work on an RTE for a subselect, whereas
|
||||
* get_attname() only works on real relations.
|
||||
* ----------
|
||||
*/
|
||||
char *
|
||||
get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
|
||||
{
|
||||
char *attname;
|
||||
|
||||
/*
|
||||
* If there is an alias, use it
|
||||
*/
|
||||
if (attnum > 0 && attnum <= length(rte->eref->attrs))
|
||||
return strVal(nth(attnum-1, rte->eref->attrs));
|
||||
/*
|
||||
* Can get here for a system attribute (which never has an alias),
|
||||
* or if alias name list is too short (which probably can't happen
|
||||
* anymore). Neither of these cases is valid for a subselect RTE.
|
||||
*/
|
||||
if (rte->relid == InvalidOid)
|
||||
elog(ERROR, "Invalid attnum %d for rangetable entry %s",
|
||||
attnum, rte->eref->relname);
|
||||
/*
|
||||
* Use the real name of the table's column
|
||||
*/
|
||||
attname = get_attname(rte->relid, attnum);
|
||||
if (attname == NULL)
|
||||
elog(ERROR, "cache lookup of attribute %d in relation %u failed",
|
||||
attnum, rte->relid);
|
||||
return attname;
|
||||
}
|
||||
|
||||
/*
|
||||
* given relation and att name, return id of variable
|
||||
*
|
||||
|
Reference in New Issue
Block a user