|
3 | 3 | * back to source text
|
4 | 4 | *
|
5 | 5 | * 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 $ |
7 | 7 | *
|
8 | 8 | * This software is copyrighted by Jan Wieck - Hamburg.
|
9 | 9 | *
|
@@ -1866,28 +1866,36 @@ get_rule_expr(Node *node, deparse_context *context)
|
1866 | 1866 | case T_FieldSelect:
|
1867 | 1867 | {
|
1868 | 1868 | FieldSelect *fselect = (FieldSelect *) node;
|
| 1869 | + Oid argType = exprType(fselect->arg); |
1869 | 1870 | HeapTuple typetup;
|
1870 | 1871 | Form_pg_type typeStruct;
|
1871 | 1872 | Oid typrelid;
|
1872 | 1873 | char *fieldname;
|
1873 | 1874 |
|
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 */ |
1876 | 1876 | typetup = SearchSysCache(TYPEOID,
|
1877 |
| - ObjectIdGetDatum(exprType(fselect->arg)), |
| 1877 | + ObjectIdGetDatum(argType), |
1878 | 1878 | 0, 0, 0);
|
1879 | 1879 | if (!HeapTupleIsValid(typetup))
|
1880 | 1880 | elog(ERROR, "cache lookup of type %u failed",
|
1881 |
| - exprType(fselect->arg)); |
| 1881 | + argType); |
1882 | 1882 | typeStruct = (Form_pg_type) GETSTRUCT(typetup);
|
1883 | 1883 | typrelid = typeStruct->typrelid;
|
1884 | 1884 | if (!OidIsValid(typrelid))
|
1885 | 1885 | elog(ERROR, "Argument type %s of FieldSelect is not a tuple type",
|
1886 |
| - NameStr(typeStruct->typname)); |
| 1886 | + format_type_be(argType)); |
| 1887 | + ReleaseSysCache(typetup); |
1887 | 1888 | fieldname = get_relid_attribute_name(typrelid,
|
1888 | 1889 | 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, ')'); |
1891 | 1899 | }
|
1892 | 1900 | break;
|
1893 | 1901 |
|
|
0 commit comments