aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser/parse_expr.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-02-14 17:34:19 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-02-14 17:34:56 -0500
commit398f70ec070fe60151584eaa448f04708aa77892 (patch)
tree508ae6812ca581b5e39e11bb80206aa87e115046 /src/backend/parser/parse_expr.c
parentc1d9df4fa227781b31be44a5a3024865a7f48049 (diff)
downloadpostgresql-398f70ec070fe60151584eaa448f04708aa77892.tar.gz
postgresql-398f70ec070fe60151584eaa448f04708aa77892.zip
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
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r--src/backend/parser/parse_expr.c14
1 files changed, 13 insertions, 1 deletions
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;