mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
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
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user