aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/execTuples.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor/execTuples.c')
-rw-r--r--src/backend/executor/execTuples.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c
index 43d047747f1..c9a3de894d8 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -985,6 +985,49 @@ ExecTypeFromExprList(List *exprList, List *namesList)
}
/*
+ * ExecTypeSetColNames - set column names in a TupleDesc
+ *
+ * Column names must be provided as an alias list (list of String nodes).
+ * We set names only in TupleDesc columns that lacked one before.
+ */
+void
+ExecTypeSetColNames(TupleDesc typeInfo, List *namesList)
+{
+ bool modified = false;
+ int colno = 0;
+ ListCell *lc;
+
+ foreach(lc, namesList)
+ {
+ char *cname = strVal(lfirst(lc));
+ Form_pg_attribute attr;
+
+ /* Guard against too-long names list */
+ if (colno >= typeInfo->natts)
+ break;
+ attr = typeInfo->attrs[colno++];
+
+ /* Ignore empty aliases (these must be for dropped columns) */
+ if (cname[0] == '\0')
+ continue;
+
+ /* Change tupdesc only if we didn't have a name before */
+ if (NameStr(attr->attname)[0] == '\0')
+ {
+ namestrcpy(&(attr->attname), cname);
+ modified = true;
+ }
+ }
+
+ /* If we modified the tupdesc, it's now a new record type */
+ if (modified)
+ {
+ typeInfo->tdtypeid = RECORDOID;
+ typeInfo->tdtypmod = -1;
+ }
+}
+
+/*
* BlessTupleDesc - make a completed tuple descriptor useful for SRFs
*
* Rowtype Datums returned by a function must contain valid type information.