From 398f70ec070fe60151584eaa448f04708aa77892 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 14 Feb 2012 17:34:19 -0500 Subject: Preserve column names in the execution-time tupledesc for a RowExpr. The hstore and json datatypes both have record-conversion functions that pay attention to column names in the composite values they're handed. We used to not worry about inserting correct field names into tuple descriptors generated at runtime, but given these examples it seems useful to do so. Observe the nicer-looking results in the regression tests whose results changed. catversion bump because there is a subtle change in requirements for stored rule parsetrees: RowExprs from ROW() constructs now have to include field names. Andrew Dunstan and Tom Lane --- src/backend/parser/parse_expr.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/backend/parser/parse_expr.c') diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 698f206f169..d22d8a12bac 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -1692,6 +1692,9 @@ static Node * transformRowExpr(ParseState *pstate, RowExpr *r) { RowExpr *newr = makeNode(RowExpr); + char fname[16]; + int fnum; + ListCell *lc; /* Transform the field expressions */ newr->args = transformExpressionList(pstate, r->args); @@ -1699,7 +1702,16 @@ transformRowExpr(ParseState *pstate, RowExpr *r) /* Barring later casting, we consider the type RECORD */ newr->row_typeid = RECORDOID; newr->row_format = COERCE_IMPLICIT_CAST; - newr->colnames = NIL; /* ROW() has anonymous columns */ + + /* ROW() has anonymous columns, so invent some field names */ + newr->colnames = NIL; + fnum = 1; + foreach(lc, newr->args) + { + snprintf(fname, sizeof(fname), "f%d", fnum++); + newr->colnames = lappend(newr->colnames, makeString(pstrdup(fname))); + } + newr->location = r->location; return (Node *) newr; -- cgit v1.2.3