MCPcopy Create free account
hub / github.com/apache/cloudberry / postquel_get_single_result

Function postquel_get_single_result

src/backend/executor/functions.c:1112–1150  ·  view source on GitHub ↗

* Extract the SQL function's value from a single result row. This is used * both for scalar (non-set) functions and for each row of a lazy-eval set * result. */

Source from the content-addressed store, hash-verified

1110 * result.
1111 */
1112static Datum
1113postquel_get_single_result(TupleTableSlot *slot,
1114 FunctionCallInfo fcinfo,
1115 SQLFunctionCachePtr fcache,
1116 MemoryContext resultcontext)
1117{
1118 Datum value;
1119 MemoryContext oldcontext;
1120
1121 /*
1122 * Set up to return the function value. For pass-by-reference datatypes,
1123 * be sure to allocate the result in resultcontext, not the current memory
1124 * context (which has query lifespan). We can't leave the data in the
1125 * TupleTableSlot because we intend to clear the slot before returning.
1126 */
1127 oldcontext = MemoryContextSwitchTo(resultcontext);
1128
1129 if (fcache->returnsTuple)
1130 {
1131 /* We must return the whole tuple as a Datum. */
1132 fcinfo->isnull = false;
1133 value = ExecFetchSlotHeapTupleDatum(slot);
1134 }
1135 else
1136 {
1137 /*
1138 * Returning a scalar, which we have to extract from the first column
1139 * of the SELECT result, and then copy into result context if needed.
1140 */
1141 value = slot_getattr(slot, 1, &(fcinfo->isnull));
1142
1143 if (!fcinfo->isnull)
1144 value = datumCopy(value, fcache->typbyval, fcache->typlen);
1145 }
1146
1147 MemoryContextSwitchTo(oldcontext);
1148
1149 return value;
1150}
1151
1152/*
1153 * fmgr_sql: function call manager for SQL functions

Callers 1

fmgr_sqlFunction · 0.85

Calls 4

MemoryContextSwitchToFunction · 0.85
slot_getattrFunction · 0.85
datumCopyFunction · 0.85

Tested by

no test coverage detected