diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-11-26 21:15:14 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-11-26 21:15:14 +0000 |
commit | 2337780e0e17a9d7e7caf72a69440e1e6c7abe4b (patch) | |
tree | fed02647ca43917b01624dd10c89126ed5760589 /src/backend/utils/adt/ruleutils.c | |
parent | 2631b7909877a3cdcdfcc6cedb57635ecf27d35e (diff) | |
download | postgresql-2337780e0e17a9d7e7caf72a69440e1e6c7abe4b.tar.gz postgresql-2337780e0e17a9d7e7caf72a69440e1e6c7abe4b.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index 421c6a828ce..27abf6ace50 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -3,7 +3,7 @@ * back to source text * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.88 2001/11/26 00:29:15 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.89 2001/11/26 21:15:14 tgl Exp $ * * This software is copyrighted by Jan Wieck - Hamburg. * @@ -1866,28 +1866,36 @@ get_rule_expr(Node *node, deparse_context *context) case T_FieldSelect: { FieldSelect *fselect = (FieldSelect *) node; + Oid argType = exprType(fselect->arg); HeapTuple typetup; Form_pg_type typeStruct; Oid typrelid; char *fieldname; - /* we do NOT parenthesize the arg expression, for now */ - get_rule_expr(fselect->arg, context); + /* lookup arg type and get the field name */ typetup = SearchSysCache(TYPEOID, - ObjectIdGetDatum(exprType(fselect->arg)), + ObjectIdGetDatum(argType), 0, 0, 0); if (!HeapTupleIsValid(typetup)) elog(ERROR, "cache lookup of type %u failed", - exprType(fselect->arg)); + argType); typeStruct = (Form_pg_type) GETSTRUCT(typetup); typrelid = typeStruct->typrelid; if (!OidIsValid(typrelid)) elog(ERROR, "Argument type %s of FieldSelect is not a tuple type", - NameStr(typeStruct->typname)); + format_type_be(argType)); + ReleaseSysCache(typetup); fieldname = get_relid_attribute_name(typrelid, fselect->fieldnum); - appendStringInfo(buf, ".%s", quote_identifier(fieldname)); - ReleaseSysCache(typetup); + /* + * If the argument is simple enough, we could emit + * arg.fieldname, but most cases where FieldSelect is used + * are *not* simple. For now, always use the projection- + * function syntax. + */ + appendStringInfo(buf, "%s(", quote_identifier(fieldname)); + get_rule_expr(fselect->arg, context); + appendStringInfoChar(buf, ')'); } break; |