mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +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:
@ -4627,7 +4627,8 @@ ExecInitExpr(Expr *node, PlanState *parent)
|
||||
if (rowexpr->row_typeid == RECORDOID)
|
||||
{
|
||||
/* generic record, use runtime type assignment */
|
||||
rstate->tupdesc = ExecTypeFromExprList(rowexpr->args);
|
||||
rstate->tupdesc = ExecTypeFromExprList(rowexpr->args,
|
||||
rowexpr->colnames);
|
||||
BlessTupleDesc(rstate->tupdesc);
|
||||
/* we won't need to redo this at runtime */
|
||||
}
|
||||
|
@ -954,27 +954,28 @@ ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk)
|
||||
/*
|
||||
* ExecTypeFromExprList - build a tuple descriptor from a list of Exprs
|
||||
*
|
||||
* Here we must make up an arbitrary set of field names.
|
||||
* Caller must also supply a list of field names (String nodes).
|
||||
*/
|
||||
TupleDesc
|
||||
ExecTypeFromExprList(List *exprList)
|
||||
ExecTypeFromExprList(List *exprList, List *namesList)
|
||||
{
|
||||
TupleDesc typeInfo;
|
||||
ListCell *l;
|
||||
ListCell *le;
|
||||
ListCell *ln;
|
||||
int cur_resno = 1;
|
||||
char fldname[NAMEDATALEN];
|
||||
|
||||
Assert(list_length(exprList) == list_length(namesList));
|
||||
|
||||
typeInfo = CreateTemplateTupleDesc(list_length(exprList), false);
|
||||
|
||||
foreach(l, exprList)
|
||||
forboth(le, exprList, ln, namesList)
|
||||
{
|
||||
Node *e = lfirst(l);
|
||||
|
||||
sprintf(fldname, "f%d", cur_resno);
|
||||
Node *e = lfirst(le);
|
||||
char *n = strVal(lfirst(ln));
|
||||
|
||||
TupleDescInitEntry(typeInfo,
|
||||
cur_resno,
|
||||
fldname,
|
||||
n,
|
||||
exprType(e),
|
||||
exprTypmod(e),
|
||||
0);
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "executor/executor.h"
|
||||
#include "executor/nodeValuesscan.h"
|
||||
#include "parser/parsetree.h"
|
||||
|
||||
|
||||
static TupleTableSlot *ValuesNext(ValuesScanState *node);
|
||||
@ -188,6 +189,8 @@ ValuesScanState *
|
||||
ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags)
|
||||
{
|
||||
ValuesScanState *scanstate;
|
||||
RangeTblEntry *rte = rt_fetch(node->scan.scanrelid,
|
||||
estate->es_range_table);
|
||||
TupleDesc tupdesc;
|
||||
ListCell *vtl;
|
||||
int i;
|
||||
@ -239,7 +242,8 @@ ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags)
|
||||
/*
|
||||
* get info about values list
|
||||
*/
|
||||
tupdesc = ExecTypeFromExprList((List *) linitial(node->values_lists));
|
||||
tupdesc = ExecTypeFromExprList((List *) linitial(node->values_lists),
|
||||
rte->eref->colnames);
|
||||
|
||||
ExecAssignScanType(&scanstate->ss, tupdesc);
|
||||
|
||||
|
Reference in New Issue
Block a user