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

Commit40136f4

Browse files
committed
Make rule lister do the right thing with Vars representing whole tuples.
1 parent4a59051 commit40136f4

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

‎src/backend/parser/parse_relation.c

Lines changed: 7 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.53 2001/03/22 03:59:41 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.54 2001/04/18 17:04:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -909,6 +909,9 @@ expandNamesVars(ParseState *pstate, List *names, List *vars)
909909
* In particular, it will work on an RTE for a subselect, whereas
910910
* get_attname() only works on real relations.
911911
*
912+
* "*" is returned if the given attnum is InvalidAttrNumber --- this case
913+
* occurs when a Var represents a whole tuple of a relation.
914+
*
912915
* XXX Actually, this is completely bogus, because refnames of RTEs are
913916
* not guaranteed unique, and may not even have scope across the whole
914917
* query. Cleanest fix would be to add refname/attname to Var nodes and
@@ -920,6 +923,9 @@ get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
920923
{
921924
char*attname;
922925

926+
if (attnum==InvalidAttrNumber)
927+
return"*";
928+
923929
/*
924930
* If there is an alias, use it
925931
*/

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

Lines changed: 22 additions & 9 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.76 2001/04/15 03:14:18 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.77 2001/04/18 17:04:24 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -1051,7 +1051,8 @@ get_basic_select_query(Query *query, deparse_context *context)
10511051
char*attname;
10521052

10531053
get_names_for_var(var,context,&refname,&attname);
1054-
tell_as= (strcmp(attname,tle->resdom->resname)!=0);
1054+
tell_as= (attname==NULL||
1055+
strcmp(attname,tle->resdom->resname)!=0);
10551056
}
10561057

10571058
/* and do if so */
@@ -1380,6 +1381,9 @@ get_utility_query_def(Query *query, deparse_context *context)
13801381
/*
13811382
* Get the relation refname and attname for a (possibly nonlocal) Var.
13821383
*
1384+
* attname will be returned as NULL if the Var represents a whole tuple
1385+
* of the relation.
1386+
*
13831387
* This is trickier than it ought to be because of the possibility of aliases
13841388
* and limited scope of refnames. We have to try to return the correct alias
13851389
* with respect to the current namespace given by the context.
@@ -1414,7 +1418,10 @@ get_names_for_var(Var *var, deparse_context *context,
14141418
*/
14151419
rte=rt_fetch(var->varno,dpns->rtable);
14161420
*refname=rte->eref->relname;
1417-
*attname=get_rte_attribute_name(rte,var->varattno);
1421+
if (var->varattno==InvalidAttrNumber)
1422+
*attname=NULL;
1423+
else
1424+
*attname=get_rte_attribute_name(rte,var->varattno);
14181425
}
14191426

14201427
/*
@@ -1474,7 +1481,10 @@ find_alias_in_namespace(Node *nsnode, Node *expr,
14741481
RangeTblEntry*rte=rt_fetch(rtindex,rangetable);
14751482

14761483
*refname=rte->eref->relname;
1477-
*attname=get_rte_attribute_name(rte,var->varattno);
1484+
if (var->varattno==InvalidAttrNumber)
1485+
*attname=NULL;
1486+
else
1487+
*attname=get_rte_attribute_name(rte,var->varattno);
14781488
return true;
14791489
}
14801490
}
@@ -1684,17 +1694,20 @@ get_rule_expr(Node *node, deparse_context *context)
16841694
char*attname;
16851695

16861696
get_names_for_var(var,context,&refname,&attname);
1687-
if (context->varprefix)
1697+
if (context->varprefix||attname==NULL)
16881698
{
16891699
if (strcmp(refname,"*NEW*")==0)
1690-
appendStringInfo(buf,"new.");
1700+
appendStringInfo(buf,"new");
16911701
elseif (strcmp(refname,"*OLD*")==0)
1692-
appendStringInfo(buf,"old.");
1702+
appendStringInfo(buf,"old");
16931703
else
1694-
appendStringInfo(buf,"%s.",
1704+
appendStringInfo(buf,"%s",
16951705
quote_identifier(refname));
1706+
if (attname)
1707+
appendStringInfoChar(buf,'.');
16961708
}
1697-
appendStringInfo(buf,"%s",quote_identifier(attname));
1709+
if (attname)
1710+
appendStringInfo(buf,"%s",quote_identifier(attname));
16981711
}
16991712
break;
17001713

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp