diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-09-25 18:14:55 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-09-25 18:14:55 +0000 |
commit | 8bdc2bf030acae0bdac98c645a3c80f205e7e10a (patch) | |
tree | 4a006a48c92f0de9945eb38a2a0b05cdf49a9514 /src/backend/parser/parse_relation.c | |
parent | 164caa3951a80d3e9f31f598460ee7582850c71b (diff) | |
download | postgresql-8bdc2bf030acae0bdac98c645a3c80f205e7e10a.tar.gz postgresql-8bdc2bf030acae0bdac98c645a3c80f205e7e10a.zip |
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.
Diffstat (limited to 'src/backend/parser/parse_relation.c')
-rw-r--r-- | src/backend/parser/parse_relation.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 491cbc5ef08..baae0a578cf 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -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 * |