Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8bdc2bf

Browse files
committed
Use variable aliases, if supplied, rather than real column names in
complaints about ungrouped variables. This is for consistency withbehavior elsewhere, notably the fact that the relname is reported asan alias in these same complaints. Also, it'll work with subselect-in-FROM where old code didn't.
1 parent164caa3 commit8bdc2bf

File tree

6 files changed

+62
-58
lines changed

6 files changed

+62
-58
lines changed

‎src/backend/nodes/print.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.40 2000/09/12 21:06:49 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/print.c,v 1.41 2000/09/25 18:14:55 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -172,11 +172,13 @@ print_expr(Node *expr, List *rtable)
172172
break;
173173
default:
174174
{
175-
RangeTblEntry*rt;
175+
RangeTblEntry*rte;
176176

177-
rt=rt_fetch(var->varno,rtable);
178-
relname=rt->eref->relname;
179-
attname=get_attname(rt->relid,var->varattno);
177+
Assert(var->varno>0&&
178+
(int)var->varno <=length(rtable));
179+
rte=rt_fetch(var->varno,rtable);
180+
relname=rte->eref->relname;
181+
attname=get_rte_attribute_name(rte,var->varattno);
180182
}
181183
break;
182184
}

‎src/backend/optimizer/util/clauses.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.74 2000/09/12 21:06:58 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.75 2000/09/25 18:14:55 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -584,12 +584,9 @@ check_subplans_for_ungrouped_vars_walker(Node *node,
584584
char*attname;
585585

586586
Assert(var->varno>0&&
587-
var->varno <=length(context->rtable));
587+
(int)var->varno <=length(context->rtable));
588588
rte=rt_fetch(var->varno,context->rtable);
589-
attname=get_attname(rte->relid,var->varattno);
590-
if (!attname)
591-
elog(ERROR,"cache lookup of attribute %d in relation %u failed",
592-
var->varattno,rte->relid);
589+
attname=get_rte_attribute_name(rte,var->varattno);
593590
elog(ERROR,"Sub-SELECT uses un-GROUPed attribute %s.%s from outer query",
594591
rte->eref->relname,attname);
595592
}

‎src/backend/parser/parse_agg.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.40 2000/09/12 21:07:02 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_agg.c,v 1.41 2000/09/25 18:14:54 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -113,10 +113,7 @@ check_ungrouped_columns_walker(Node *node,
113113
Assert(var->varno>0&&
114114
(int)var->varno <=length(context->pstate->p_rtable));
115115
rte=rt_fetch(var->varno,context->pstate->p_rtable);
116-
attname=get_attname(rte->relid,var->varattno);
117-
if (!attname)
118-
elog(ERROR,"cache lookup of attribute %d in relation %u failed",
119-
var->varattno,rte->relid);
116+
attname=get_rte_attribute_name(rte,var->varattno);
120117
elog(ERROR,"Attribute %s.%s must be GROUPed or used in an aggregate function",
121118
rte->eref->relname,attname);
122119
}

‎src/backend/parser/parse_relation.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.47 2000/09/12 21:07:02 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.48 2000/09/25 18:14:54 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -713,6 +713,43 @@ expandNamesVars(ParseState *pstate, List *names, List *vars)
713713
returnte_list;
714714
}
715715

716+
/* ----------
717+
* get_rte_attribute_name
718+
*Get an attribute name from a RangeTblEntry
719+
*
720+
* This is unlike get_attname() because we use aliases if available.
721+
* In particular, it will work on an RTE for a subselect, whereas
722+
* get_attname() only works on real relations.
723+
* ----------
724+
*/
725+
char*
726+
get_rte_attribute_name(RangeTblEntry*rte,AttrNumberattnum)
727+
{
728+
char*attname;
729+
730+
/*
731+
* If there is an alias, use it
732+
*/
733+
if (attnum>0&&attnum <=length(rte->eref->attrs))
734+
returnstrVal(nth(attnum-1,rte->eref->attrs));
735+
/*
736+
* Can get here for a system attribute (which never has an alias),
737+
* or if alias name list is too short (which probably can't happen
738+
* anymore). Neither of these cases is valid for a subselect RTE.
739+
*/
740+
if (rte->relid==InvalidOid)
741+
elog(ERROR,"Invalid attnum %d for rangetable entry %s",
742+
attnum,rte->eref->relname);
743+
/*
744+
* Use the real name of the table's column
745+
*/
746+
attname=get_attname(rte->relid,attnum);
747+
if (attname==NULL)
748+
elog(ERROR,"cache lookup of attribute %d in relation %u failed",
749+
attnum,rte->relid);
750+
returnattname;
751+
}
752+
716753
/*
717754
*given relation and att name, return id of variable
718755
*

‎src/backend/utils/adt/ruleutils.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*back to source text
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.62 2000/09/18 20:14:23 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.63 2000/09/25 18:14:54 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -110,7 +110,6 @@ static bool tleIsArrayAssign(TargetEntry *tle);
110110
staticchar*quote_identifier(char*ident);
111111
staticchar*get_relation_name(Oidrelid);
112112
staticchar*get_relid_attribute_name(Oidrelid,AttrNumberattnum);
113-
staticchar*get_rte_attribute_name(RangeTblEntry*rte,AttrNumberattnum);
114113

115114
#defineonly_marker(rte) ((rte)->inh ? "" : "ONLY ")
116115

@@ -2020,33 +2019,3 @@ get_relid_attribute_name(Oid relid, AttrNumber attnum)
20202019
attnum,relid);
20212020
returnattname;
20222021
}
2023-
2024-
/* ----------
2025-
* get_rte_attribute_name
2026-
*Get an attribute name from a RangeTblEntry
2027-
*
2028-
* This is unlike get_relid_attribute_name() because we use aliases if
2029-
* available.
2030-
* ----------
2031-
*/
2032-
staticchar*
2033-
get_rte_attribute_name(RangeTblEntry*rte,AttrNumberattnum)
2034-
{
2035-
/*
2036-
* If there is an alias, use it
2037-
*/
2038-
if (attnum>0&&attnum <=length(rte->eref->attrs))
2039-
returnstrVal(nth(attnum-1,rte->eref->attrs));
2040-
/*
2041-
* Can get here for a system attribute (which never has an alias),
2042-
* or if alias name list is too short (which probably can't happen
2043-
* anymore). Neither of these cases is valid for a subselect RTE.
2044-
*/
2045-
if (rte->relid==InvalidOid)
2046-
elog(ERROR,"Invalid attnum %d for rangetable entry %s",
2047-
attnum,rte->eref->relname);
2048-
/*
2049-
* Use the real name of the table's column
2050-
*/
2051-
returnget_relid_attribute_name(rte->relid,attnum);
2052-
}

‎src/include/parser/parsetree.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@
88
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $Id: parsetree.h,v 1.11 2000/09/12 21:07:12 tgl Exp $
11+
* $Id: parsetree.h,v 1.12 2000/09/25 18:14:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#ifndefPARSETREE_H
1616
#definePARSETREE_H
1717

1818
#include"nodes/parsenodes.h"
19-
#include"nodes/pg_list.h"
19+
#include"nodes/pg_list.h"/* for nth(), etc */
2020

21-
/* ----------------
22-
*need pg_list.h for definitions of nth(), etc.
23-
* ----------------
24-
*/
2521

2622
/* ----------------
2723
*range table macros
@@ -33,10 +29,9 @@
3329
*rt_store
3430
*
3531
*Access and (destructively) replace rangetable entries.
36-
*
3732
*/
3833
#definert_fetch(rangetable_index,rangetable) \
39-
((RangeTblEntry*) nth((rangetable_index)-1, rangetable))
34+
((RangeTblEntry*) nth((rangetable_index)-1, rangetable))
4035

4136
#definert_store(rangetable_index,rangetable,rt) \
4237
set_nth(rangetable, (rangetable_index)-1, rt)
@@ -45,9 +40,16 @@
4540
*getrelid
4641
*
4742
*Given the range index of a relation, return the corresponding
48-
*relation OID.
43+
*relation OID. Note that InvalidOid will be returned if the
44+
*RTE is for a sub-select rather than a relation.
4945
*/
5046
#definegetrelid(rangeindex,rangetable) \
5147
(rt_fetch(rangeindex, rangetable)->relid)
5248

49+
/*
50+
* Given an RTE and an attribute number, return the appropriate
51+
* variable name or alias for that attribute of that RTE.
52+
*/
53+
externchar*get_rte_attribute_name(RangeTblEntry*rte,AttrNumberattnum);
54+
5355
#endif/* PARSETREE_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp