Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2337780

Browse files
committed
Change display of FieldSelect nodes from arg.field to field(arg),
per bug report from Stefan Hadjistoytchev. There are some cases where the dot notation works, but there are more where it doesn't. Eventually ought to consider fixing the parser to allow cases like func().field, but for now this is the simplest patch.
1 parent 2631b79 commit 2337780

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 16 additions & 8 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.88 2001/11/26 00:29:15 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.89 2001/11/26 21:15:14 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -1866,28 +1866,36 @@ get_rule_expr(Node *node, deparse_context *context)
18661866
case T_FieldSelect:
18671867
{
18681868
FieldSelect *fselect = (FieldSelect *) node;
1869+
Oid argType = exprType(fselect->arg);
18691870
HeapTuple typetup;
18701871
Form_pg_type typeStruct;
18711872
Oid typrelid;
18721873
char *fieldname;
18731874

1874-
/* we do NOT parenthesize the arg expression, for now */
1875-
get_rule_expr(fselect->arg, context);
1875+
/* lookup arg type and get the field name */
18761876
typetup = SearchSysCache(TYPEOID,
1877-
ObjectIdGetDatum(exprType(fselect->arg)),
1877+
ObjectIdGetDatum(argType),
18781878
0, 0, 0);
18791879
if (!HeapTupleIsValid(typetup))
18801880
elog(ERROR, "cache lookup of type %u failed",
1881-
exprType(fselect->arg));
1881+
argType);
18821882
typeStruct = (Form_pg_type) GETSTRUCT(typetup);
18831883
typrelid = typeStruct->typrelid;
18841884
if (!OidIsValid(typrelid))
18851885
elog(ERROR, "Argument type %s of FieldSelect is not a tuple type",
1886-
NameStr(typeStruct->typname));
1886+
format_type_be(argType));
1887+
ReleaseSysCache(typetup);
18871888
fieldname = get_relid_attribute_name(typrelid,
18881889
fselect->fieldnum);
1889-
appendStringInfo(buf, ".%s", quote_identifier(fieldname));
1890-
ReleaseSysCache(typetup);
1890+
/*
1891+
* If the argument is simple enough, we could emit
1892+
* arg.fieldname, but most cases where FieldSelect is used
1893+
* are *not* simple. For now, always use the projection-
1894+
* function syntax.
1895+
*/
1896+
appendStringInfo(buf, "%s(", quote_identifier(fieldname));
1897+
get_rule_expr(fselect->arg, context);
1898+
appendStringInfoChar(buf, ')');
18911899
}
18921900
break;
18931901

0 commit comments

Comments
 (0)