61 state->funcReturnsSet =
false;
78 state->funcReturnsSet = func->funcretset;
111 bool returnsSet =
false;
117 bool first_time =
true;
146 rsinfo.
type = T_ReturnSetInfo;
178 NULL, (
Node *) &rsinfo);
195 goto no_function_result;
314 (
errcode(ERRCODE_DATATYPE_MISMATCH),
315 errmsg(
"rows returned by function are not all of the same row type")));
337 int natts = expectedDesc->
natts;
340 nullflags = (
bool *)
palloc(natts *
sizeof(
bool));
341 memset(nullflags,
true, natts *
sizeof(
bool));
364 (
errcode(ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED),
365 errmsg(
"table-function protocol for value-per-call mode was not followed")));
372 (
errcode(ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED),
373 errmsg(
"table-function protocol for materialize mode was not followed")));
379 (
errcode(ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED),
380 errmsg(
"unrecognized table-function returnMode: %d",
405 int natts = expectedDesc->
natts;
408 nullflags = (
bool *)
palloc(natts *
sizeof(
bool));
409 memset(nullflags,
true, natts *
sizeof(
bool));
449 state->funcReturnsSet =
true;
474 elog(
ERROR,
"unrecognized node type: %d",
591 rsinfo.
type = T_ReturnSetInfo;
666 (
errcode(ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED),
667 errmsg(
"table-function protocol for materialize mode was not followed")));
684 (
errcode(ERRCODE_E_R_I_E_SRF_PROTOCOL_VIOLATED),
685 errmsg(
"unrecognized table-function returnMode: %d",
717 (
errcode(ERRCODE_TOO_MANY_ARGUMENTS),
718 errmsg_plural(
"cannot pass more than %d argument to a function",
719 "cannot pass more than %d arguments to a function",
732 input_collation, NULL, NULL);
737 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
738 errmsg(
"set-valued function called in context that cannot accept a set"),
842 foreach(
arg, argList)
893 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
894 errmsg(
"function returning setof record called in "
895 "context that cannot accept type record")));
949 (
errcode(ERRCODE_DATATYPE_MISMATCH),
950 errmsg(
"function return row and query-specified return row do not match"),
951 errdetail_plural(
"Returned row contains %d attribute, but query expects %d.",
952 "Returned row contains %d attributes, but query expects %d.",
956 for (
i = 0;
i < dst_tupdesc->
natts;
i++)
963 if (!dattr->attisdropped)
965 (
errcode(ERRCODE_DATATYPE_MISMATCH),
966 errmsg(
"function return row and query-specified return row do not match"),
967 errdetail(
"Returned type %s at ordinal position %d, but query expects %s.",
972 if (dattr->attlen != sattr->attlen ||
973 dattr->attalign != sattr->attalign)
975 (
errcode(ERRCODE_DATATYPE_MISMATCH),
976 errmsg(
"function return row and query-specified return row do not match"),
977 errdetail(
"Physical storage mismatch on dropped attribute at ordinal position %d.",
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
#define Assert(condition)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errdetail(const char *fmt,...)
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
List * ExecInitExprList(List *nodes, PlanState *parent)
static void init_sexpr(Oid foid, Oid input_collation, Expr *node, SetExprState *sexpr, PlanState *parent, MemoryContext sexprCxt, bool allowSRF, bool needDescForSRF)
SetExprState * ExecInitFunctionResultSet(Expr *expr, ExprContext *econtext, PlanState *parent)
Tuplestorestate * ExecMakeTableFunctionResult(SetExprState *setexpr, ExprContext *econtext, MemoryContext argContext, TupleDesc expectedDesc, bool randomAccess)
Datum ExecMakeFunctionResultSet(SetExprState *fcache, ExprContext *econtext, MemoryContext argContext, bool *isNull, ExprDoneCond *isDone)
SetExprState * ExecInitTableFunctionResult(Expr *expr, ExprContext *econtext, PlanState *parent)
static void ExecEvalFuncArgs(FunctionCallInfo fcinfo, List *argList, ExprContext *econtext)
static void ShutdownSetExpr(Datum arg)
static void ExecPrepareTuplestoreResult(SetExprState *sexpr, ExprContext *econtext, Tuplestorestate *resultStore, TupleDesc resultDesc)
static void tupledesc_match(TupleDesc dst_tupdesc, TupleDesc src_tupdesc)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Datum ExecFetchSlotHeapTupleDatum(TupleTableSlot *slot)
const TupleTableSlotOps TTSOpsMinimalTuple
int executor_errposition(EState *estate, int location)
void RegisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
@ SFRM_Materialize_Preferred
@ SFRM_Materialize_Random
#define ResetExprContext(econtext)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
#define DatumGetHeapTupleHeader(X)
#define SizeForFunctionCallInfo(nargs)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
struct FunctionCallInfoBaseData * FunctionCallInfo
#define FunctionCallInvoke(fcinfo)
#define fmgr_info_set_expr(expr, finfo)
TypeFuncClass get_expr_result_type(Node *expr, Oid *resultTypeId, TupleDesc *resultTupleDesc)
@ TYPEFUNC_COMPOSITE_DOMAIN
#define HeapTupleHeaderGetTypMod(tup)
#define HeapTupleHeaderGetTypeId(tup)
#define HeapTupleHeaderGetDatumLength(tup)
bool type_is_rowtype(Oid typid)
char * get_func_name(Oid funcid)
void MemoryContextReset(MemoryContext context)
MemoryContext CurrentMemoryContext
#define CHECK_FOR_INTERRUPTS()
Oid exprType(const Node *expr)
int exprLocation(const Node *expr)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
#define InvokeFunctionExecuteHook(objectId)
bool IsBinaryCoercible(Oid srctype, Oid targettype)
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
MemoryContextSwitchTo(old_ctx)
void check_stack_depth(void)
MemoryContext ecxt_per_tuple_memory
MemoryContext ecxt_per_query_memory
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
SetFunctionReturnMode returnMode
Tuplestorestate * setResult
TupleTableSlot * funcResultSlot
Tuplestorestate * funcResultStore
ExprState * elidedFuncState
void FreeTupleDesc(TupleDesc tupdesc)
TupleDesc CreateTemplateTupleDesc(int natts)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
void tuplestore_end(Tuplestorestate *state)
void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod)