43#include "utils/fmgroids.h"
127#define get_eval_mcontext(estate) \
128 ((estate)->eval_econtext->ecxt_per_tuple_memory)
129#define eval_mcontext_alloc(estate, sz) \
130 MemoryContextAlloc(get_eval_mcontext(estate), sz)
131#define eval_mcontext_alloc0(estate, sz) \
132 MemoryContextAllocZero(get_eval_mcontext(estate), sz)
204#define LOOP_RC_PROCESSING(looplabel, exit_action) \
205 if (rc == PLPGSQL_RC_RETURN) \
210 else if (rc == PLPGSQL_RC_EXIT) \
212 if (estate->exitlabel == NULL) \
215 rc = PLPGSQL_RC_OK; \
218 else if ((looplabel) != NULL && \
219 strcmp(looplabel, estate->exitlabel) == 0) \
222 estate->exitlabel = NULL; \
223 rc = PLPGSQL_RC_OK; \
232 else if (rc == PLPGSQL_RC_CONTINUE) \
234 if (estate->exitlabel == NULL) \
237 rc = PLPGSQL_RC_OK; \
239 else if ((looplabel) != NULL && \
240 strcmp(looplabel, estate->exitlabel) == 0) \
243 estate->exitlabel = NULL; \
244 rc = PLPGSQL_RC_OK; \
253 Assert(rc == PLPGSQL_RC_OK)
340 EState *simple_eval_estate,
390 Portal portal,
bool prefetch_ok);
394 int paramid,
bool speculative,
398 Datum *resv,
bool *resnull);
455 Datum newvalue,
bool isnull,
bool freeable);
464 const char *portalname,
int cursorOptions);
494 EState *simple_eval_estate,
508 simple_eval_estate, simple_eval_resowner);
516 plerrcontext.
arg = &estate;
629 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
640 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
641 errmsg(
"control reached end of function without RETURN")));
658 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
659 errmsg(
"set-valued function called in context that cannot accept a set")));
663 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
664 errmsg(
"materialize mode required, but it is not allowed in this context")));
746 elog(
ERROR,
"return type must be a row type");
797 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
846 gettext_noop(
"returned record type does not match expected record type"));
910 gettext_noop(
"returned record type does not match expected record type"));
956 plerrcontext.
arg = &estate;
1015 for (
int i = 0;
i < tupdesc->
natts;
i++)
1016 if (
TupleDescAttr(tupdesc,
i)->attgenerated == ATTRIBUTE_GENERATED_STORED)
1030 elog(
ERROR,
"unrecognized trigger action: not INSERT, DELETE, or UPDATE");
1047 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
1058 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
1059 errmsg(
"control reached end of trigger procedure without RETURN")));
1066 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1067 errmsg(
"trigger procedure cannot return a set")));
1106 gettext_noop(
"returned row structure does not match the structure of the triggering table"));
1134 gettext_noop(
"returned row structure does not match the structure of the triggering table"));
1151 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
1191 plerrcontext.
arg = &estate;
1205 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
1216 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
1217 errmsg(
"control reached end of trigger procedure without RETURN")));
1226 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
1275 errcontext(
"PL/pgSQL function %s line %d %s",
1291 else if (estate->
err_stmt != NULL && err_lineno > 0)
1294 errcontext(
"PL/pgSQL function %s line %d at %s",
1313 int ndatums = estate->
ndatums;
1329 ws_next = workspace;
1333 outdatums = estate->
datums;
1334 for (
i = 0;
i < ndatums;
i++)
1340 switch (indatum->
dtype)
1372 outdatums[
i] = outdatum;
1405 elog(
ERROR,
"trigger promise is not in a trigger function");
1414 elog(
ERROR,
"trigger promise is not in a trigger function");
1422 elog(
ERROR,
"unrecognized trigger execution time: not BEFORE, AFTER, or INSTEAD OF");
1427 elog(
ERROR,
"trigger promise is not in a trigger function");
1433 elog(
ERROR,
"unrecognized trigger event type: not ROW or STATEMENT");
1438 elog(
ERROR,
"trigger promise is not in a trigger function");
1448 elog(
ERROR,
"unrecognized trigger action: not INSERT, DELETE, UPDATE, or TRUNCATE");
1453 elog(
ERROR,
"trigger promise is not in a trigger function");
1461 elog(
ERROR,
"trigger promise is not in a trigger function");
1470 elog(
ERROR,
"trigger promise is not in a trigger function");
1479 elog(
ERROR,
"trigger promise is not in a trigger function");
1487 elog(
ERROR,
"trigger promise is not in a trigger function");
1501 for (
i = 0;
i < nelems;
i++)
1510 -1,
false, TYPALIGN_INT)),
1521 elog(
ERROR,
"event trigger promise is not in an event trigger function");
1527 elog(
ERROR,
"event trigger promise is not in an event trigger function");
1550 "PLpgSQL per-statement data",
1597 for (; cond != NULL; cond = cond->
next)
1608 if (edata->
sqlerrcode != ERRCODE_QUERY_CANCELED &&
1642 ((*plpgsql_plugin_ptr)->stmt_beg) (estate, (
PLpgSQL_stmt *) block);
1650 ((*plpgsql_plugin_ptr)->stmt_end) (estate, (
PLpgSQL_stmt *) block);
1665 volatile int rc = -1;
1690 switch (datum->
dtype)
1824 resTypByVal, resTypLen);
1975 if (block->
label == NULL)
2021 ((*plpgsql_plugin_ptr)->stmt_beg) (estate,
stmt);
2025 switch (
stmt->cmd_type)
2144 ((*plpgsql_plugin_ptr)->stmt_end) (estate,
stmt);
2209 if (expr->
plan == NULL)
2222 if (
stmt->is_call &&
stmt->target == NULL)
2239 options.allow_nonatomic =
true;
2245 elog(
ERROR,
"SPI_execute_plan_extended failed executing query \"%s\": %s",
2250 if (before_lxid != after_lxid)
2270 elog(
ERROR,
"DO statement returned a row");
2275 elog(
ERROR,
"procedure call returned more than one row");
2315 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2319 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2321 funcexpr =
stmt->funcexpr;
2326 elog(
ERROR,
"cache lookup failed for function %u",
2345 row->
refname =
"(unnamed row)";
2357 for (
i = 0;
i < numargs;
i++)
2360 (argmodes[
i] == PROARGMODE_INOUT ||
2361 argmodes[
i] == PROARGMODE_OUT))
2374 row->
varnos[nfields++] = dno;
2379 if (argnames && argnames[
i] && argnames[
i][0])
2381 (
errcode(ERRCODE_SYNTAX_ERROR),
2382 errmsg(
"procedure parameter \"%s\" is an output parameter but corresponding argument is not writable",
2386 (
errcode(ERRCODE_SYNTAX_ERROR),
2387 errmsg(
"procedure parameter %d is an output parameter but corresponding argument is not writable",
2422 (
errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER),
2423 errmsg(
"GET STACKED DIAGNOSTICS cannot be used outside an exception handler")));
2425 foreach(lc,
stmt->diag_items)
2430 switch (diag_item->
kind)
2435 false, INT8OID, -1);
2496 char *contextstackstr;
2509 elog(
ERROR,
"unrecognized diagnostic item kind: %d",
2534 if (!isnull &&
value)
2537 foreach(lc,
stmt->elsif_list)
2543 if (!isnull &&
value)
2562 if (
stmt->t_expr != NULL)
2570 &isnull, &t_typoid, &t_typmod);
2601 foreach(l,
stmt->case_when_list)
2608 if (!isnull &&
value)
2626 if (!
stmt->have_else)
2628 (
errcode(ERRCODE_CASE_NOT_FOUND),
2629 errmsg(
"case not found"),
2630 errhint(
"CASE statement is missing ELSE part.")));
2677 if (isnull || !
value)
2715 &isnull, &valtype, &valtypmod);
2722 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2723 errmsg(
"lower bound of FOR loop cannot be null")));
2731 &isnull, &valtype, &valtypmod);
2738 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2739 errmsg(
"upper bound of FOR loop cannot be null")));
2749 &isnull, &valtype, &valtypmod);
2756 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2757 errmsg(
"BY value of FOR loop cannot be null")));
2760 if (step_value <= 0)
2762 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2763 errmsg(
"BY value of FOR loop must be greater than zero")));
2778 if (loop_value < end_value)
2783 if (loop_value > end_value)
2809 loop_value -= step_value;
2815 loop_value += step_value;
2872 char *curname = NULL;
2896 (
errcode(ERRCODE_DUPLICATE_CURSOR),
2897 errmsg(
"cursor \"%s\" already in use", curname)));
2907 if (
stmt->argquery != NULL)
2919 (
errcode(ERRCODE_SYNTAX_ERROR),
2920 errmsg(
"arguments given for cursor without arguments")));
2922 memset(&set_args, 0,
sizeof(set_args));
2926 set_args.
into =
true;
2932 elog(
ERROR,
"open cursor failed during argument processing");
2938 (
errcode(ERRCODE_SYNTAX_ERROR),
2939 errmsg(
"arguments required for cursor")));
2945 if (query->
plan == NULL)
2960 elog(
ERROR,
"could not open cursor: %s",
2967 if (curname == NULL)
2992 if (curname == NULL)
3014 Oid loop_var_elem_type;
3020 Oid iterator_result_type;
3021 int32 iterator_result_typmod;
3029 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3030 errmsg(
"FOREACH expression must not be null")));
3044 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3045 errmsg(
"FOREACH expression must yield an array, not type %s",
3061 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3062 errmsg(
"slice dimension (%d) is out of the valid range 0..%d",
3088 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3089 errmsg(
"FOREACH ... SLICE loop variable must be of an array type")));
3092 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3093 errmsg(
"FOREACH loop variable must not be of an array type")));
3099 if (
stmt->slice > 0)
3102 iterator_result_type = arrtype;
3103 iterator_result_typmod = arrtypmod;
3109 iterator_result_typmod = arrtypmod;
3122 iterator_result_type, iterator_result_typmod);
3125 if (
stmt->slice > 0)
3169 if (
stmt->cond != NULL)
3176 if (isnull ||
value ==
false)
3224 if (
stmt->retvarno >= 0)
3228 switch (retvar->
dtype)
3254 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3255 errmsg(
"cannot return non-composite value from function returning composite type")));
3295 if (
stmt->expr != NULL)
3311 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3312 errmsg(
"cannot return non-composite value from function returning composite type")));
3350 (
errcode(ERRCODE_SYNTAX_ERROR),
3351 errmsg(
"cannot use RETURN NEXT in a non-SETOF function")));
3358 natts = tupdesc->
natts;
3370 if (
stmt->retvarno >= 0)
3374 switch (retvar->
dtype)
3386 bool isNull = var->
isnull;
3391 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3392 errmsg(
"wrong result type supplied in RETURN NEXT")));
3420 if (rec->
erh == NULL)
3430 gettext_noop(
"wrong record type supplied in RETURN NEXT"));
3450 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3451 errmsg(
"wrong record type supplied in RETURN NEXT")));
3462 else if (
stmt->expr)
3486 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3487 errmsg(
"cannot return non-composite value from function returning composite type")));
3494 gettext_noop(
"returned record type does not match expected record type"));
3507 nulldatums = (
Datum *)
3509 nullflags = (
bool *)
3511 memset(nullflags,
true, natts *
sizeof(
bool));
3513 nulldatums, nullflags);
3523 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3524 errmsg(
"wrong result type supplied in RETURN NEXT")));
3542 (
errcode(ERRCODE_SYNTAX_ERROR),
3543 errmsg(
"RETURN NEXT must have a parameter")));
3570 (
errcode(ERRCODE_SYNTAX_ERROR),
3571 errmsg(
"cannot use RETURN QUERY in a non-SETOF function")));
3589 gettext_noop(
"structure of query does not match function result type"));
3592 if (
stmt->query != NULL)
3602 if (expr->
plan == NULL)
3616 options.must_return_tuples =
true;
3621 elog(
ERROR,
"SPI_execute_plan_extended failed executing query \"%s\": %s",
3640 &isnull, &restype, &restypmod);
3643 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3644 errmsg(
"query string argument of EXECUTE is null")));
3659 options.must_return_tuples =
true;
3664 elog(
ERROR,
"SPI_execute_extended failed executing query \"%s\": %s",
3694 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3695 errmsg(
"set-valued function called in context that cannot accept a set")));
3700 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3701 errmsg(
"materialize mode required, but it is not allowed in this context")));
3724#define SET_RAISE_OPTION_TEXT(opt, name) \
3728 (errcode(ERRCODE_SYNTAX_ERROR), \
3729 errmsg("RAISE option already specified: %s", \
3731 opt = MemoryContextStrdup(stmt_mcontext, extval); \
3742 char *condname = NULL;
3743 char *err_message = NULL;
3744 char *err_detail = NULL;
3745 char *err_hint = NULL;
3746 char *err_column = NULL;
3747 char *err_constraint = NULL;
3748 char *err_datatype = NULL;
3749 char *err_table = NULL;
3750 char *err_schema = NULL;
3755 if (
stmt->condname == NULL &&
stmt->message == NULL &&
3762 (
errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER),
3763 errmsg(
"RAISE without parameters cannot be used outside an exception handler")));
3789 for (cp =
stmt->message; *cp; cp++)
3811 if (current_param == NULL)
3812 elog(
ERROR,
"unexpected RAISE parameter list length");
3827 current_param =
lnext(
stmt->params, current_param);
3835 if (current_param != NULL)
3836 elog(
ERROR,
"unexpected RAISE parameter list length");
3838 err_message = ds.
data;
3841 foreach(lc,
stmt->options)
3856 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3857 errmsg(
"RAISE statement option cannot be null")));
3866 (
errcode(ERRCODE_SYNTAX_ERROR),
3867 errmsg(
"RAISE option already specified: %s",
3904 if (err_code == 0 &&
stmt->elog_level >=
ERROR)
3905 err_code = ERRCODE_RAISE_EXCEPTION;
3908 if (err_message == NULL)
3912 err_message = condname;
3924 (err_code ?
errcode(err_code) : 0,
3927 (err_hint != NULL) ?
errhint(
"%s", err_hint) : 0,
3928 (err_column != NULL) ?
3930 (err_constraint != NULL) ?
3932 (err_datatype != NULL) ?
3934 (err_table != NULL) ?
3936 (err_schema != NULL) ?
3962 if (isnull || !
value)
3964 char *message = NULL;
3966 if (
stmt->message != NULL)
3973 &isnull, &
typeid, &typmod);
3980 (
errcode(ERRCODE_ASSERT_FAILURE),
3982 errmsg(
"assertion failed")));
3996 EState *simple_eval_estate,
4004 estate->
func = func;
4064 if (simple_eval_estate)
4092 if (simple_eval_resowner)
4137 if ((*plpgsql_plugin_ptr)->func_setup)
4138 ((*plpgsql_plugin_ptr)->func_setup) (estate, func);
4198 options.parserSetupArg = expr;
4200 options.cursorOptions = cursorOptions;
4203 elog(
ERROR,
"SPI_prepare_extended failed for \"%s\": %s",
4229 int too_many_rows_level = 0;
4232 too_many_rows_level =
ERROR;
4234 too_many_rows_level =
WARNING;
4240 if (expr->
plan == NULL)
4243 if (!
stmt->mod_stmt_set)
4247 stmt->mod_stmt =
false;
4259 if (plansource->
commandTag == CMDTAG_INSERT ||
4264 stmt->mod_stmt =
true;
4268 stmt->mod_stmt_set =
true;
4290 if (
stmt->strict ||
stmt->mod_stmt || too_many_rows_level)
4347 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4348 errmsg(
"cannot COPY to/from client in PL/pgSQL")));
4353 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4354 errmsg(
"unsupported transaction command in PL/pgSQL")));
4358 elog(
ERROR,
"SPI_execute_plan_with_paramlist failed executing query \"%s\": %s",
4376 (
errcode(ERRCODE_SYNTAX_ERROR),
4377 errmsg(
"INTO used with a command that cannot return data")));
4399 (
errcode(ERRCODE_NO_DATA_FOUND),
4400 errmsg(
"query returned no rows"),
4408 if (n > 1 && (
stmt->strict ||
stmt->mod_stmt || too_many_rows_level))
4418 errlevel = (
stmt->strict ||
stmt->mod_stmt) ?
ERROR : too_many_rows_level;
4421 (
errcode(ERRCODE_TOO_MANY_ROWS),
4422 errmsg(
"query returned more than one row"),
4424 errhint(
"Make sure the query returns a single row, or use LIMIT 1.")));
4439 (
errcode(ERRCODE_SYNTAX_ERROR),
4440 errmsg(
"query has no destination for result data"),
4441 (rc ==
SPI_OK_SELECT) ?
errhint(
"If you want to discard the results of a SELECT, use PERFORM instead.") : 0));
4474 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4475 errmsg(
"query string argument of EXECUTE is null")));
4529 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4530 errmsg(
"EXECUTE of SELECT ... INTO is not implemented"),
4531 errhint(
"You might want to use EXECUTE ... INTO or EXECUTE CREATE TABLE ... AS instead.")));
4537 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4538 errmsg(
"cannot COPY to/from client in PL/pgSQL")));
4543 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4544 errmsg(
"EXECUTE of transaction commands is not implemented")));
4548 elog(
ERROR,
"SPI_execute_extended failed executing query \"%s\": %s",
4566 (
errcode(ERRCODE_SYNTAX_ERROR),
4567 errmsg(
"INTO used with a command that cannot return data")));
4589 (
errcode(ERRCODE_NO_DATA_FOUND),
4590 errmsg(
"query returned no rows"),
4598 if (n > 1 &&
stmt->strict)
4608 (
errcode(ERRCODE_TOO_MANY_ROWS),
4609 errmsg(
"query returned more than one row"),
4675 char *curname = NULL;
4698 (
errcode(ERRCODE_DUPLICATE_CURSOR),
4699 errmsg(
"cursor \"%s\" already in use", curname)));
4706 if (
stmt->query != NULL)
4715 query =
stmt->query;
4716 if (query->
plan == NULL)
4719 else if (
stmt->dynquery != NULL)
4729 stmt->cursor_options);
4739 if (curname == NULL)
4756 if (
stmt->argquery != NULL)
4768 (
errcode(ERRCODE_SYNTAX_ERROR),
4769 errmsg(
"arguments given for cursor without arguments")));
4771 memset(&set_args, 0,
sizeof(set_args));
4775 set_args.
into =
true;
4781 elog(
ERROR,
"open cursor failed during argument processing");
4787 (
errcode(ERRCODE_SYNTAX_ERROR),
4788 errmsg(
"arguments required for cursor")));
4792 if (query->
plan == NULL)
4808 elog(
ERROR,
"could not open cursor: %s",
4815 if (curname == NULL)
4839 long how_many =
stmt->how_many;
4853 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4854 errmsg(
"cursor variable \"%s\" is null", curvar->
refname)));
4864 (
errcode(ERRCODE_UNDEFINED_CURSOR),
4865 errmsg(
"cursor \"%s\" does not exist", curname)));
4877 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4878 errmsg(
"relative or absolute cursor position is null")));
4941 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4942 errmsg(
"cursor variable \"%s\" is null", curvar->
refname)));
4952 (
errcode(ERRCODE_UNDEFINED_CURSOR),
4953 errmsg(
"cursor \"%s\" does not exist", curname)));
5028 if (expr->
plan == NULL)
5080 switch (target->
dtype)
5101 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5102 errmsg(
"null value cannot be assigned to variable \"%s\" declared NOT NULL",
5151 if (var->
value != newvalue || var->
isnull || isNull)
5177 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5178 errmsg(
"cannot assign non-composite value to a row variable")));
5196 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5197 errmsg(
"null value cannot be assigned to variable \"%s\" declared NOT NULL",
5209 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5210 errmsg(
"cannot assign non-composite value to a record variable")));
5251 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5252 errmsg(
"record \"%s\" has no field \"%s\"",
5260 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5261 errmsg(
"cannot assign to system column \"%s\"",
5311 switch (datum->
dtype)
5337 elog(
ERROR,
"row variable has no tupdesc");
5343 elog(
ERROR,
"row not compatible with its own tupdesc");
5356 if (rec->
erh == NULL)
5424 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5425 errmsg(
"record \"%s\" has no field \"%s\"",
5458 switch (datum->
dtype)
5498 if (rec->
erh == NULL)
5511 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5512 errmsg(
"record \"%s\" has no field \"%s\"",
5542 switch (datum->
dtype)
5589 if (rec->
erh == NULL)
5602 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5603 errmsg(
"record \"%s\" has no field \"%s\"",
5641 exprdatum =
exec_eval_expr(estate, expr, isNull, &exprtypeid, &exprtypmod);
5643 exprtypeid, exprtypmod,
5664 exprdatum =
exec_eval_expr(estate, expr, isNull, &exprtypeid, &exprtypmod);
5666 exprtypeid, exprtypmod,
5692 if (expr->
plan == NULL)
5700 &result, isNull, rettype, rettypmod))
5709 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
5710 errmsg(
"query did not return data"),
5718 (
errcode(ERRCODE_SYNTAX_ERROR),
5720 "query returned %d columns",
5729 *rettype = attr->atttypid;
5730 *rettypmod = attr->atttypmod;
5746 (
errcode(ERRCODE_CARDINALITY_VIOLATION),
5747 errmsg(
"query returned more than one row"),
5780 if (expr->
plan == NULL)
5784 if (portalP == NULL)
5797 if (portalP != NULL)
5802 if (*portalP == NULL)
5803 elog(
ERROR,
"could not open implicit cursor for query \"%s\": %s",
5822 (
errcode(ERRCODE_SYNTAX_ERROR),
5823 errmsg(
"query is SELECT INTO, but it should be plain SELECT"),
5827 (
errcode(ERRCODE_SYNTAX_ERROR),
5828 errmsg(
"query is not a SELECT"),
5848 Portal portal,
bool prefetch_ok)
5855 bool tupdescs_match =
true;
5876 prefetch_ok =
false;
5906 for (
i = 0;
i < n;
i++)
6039 void *save_setup_arg;
6309 int paramid,
bool speculative,
6321 Assert(dno >= 0 && dno < params->numParams);
6329 datum = estate->
datums[dno];
6345 else if (speculative)
6347 switch (datum->
dtype)
6372 if (rec->
erh == NULL)
6409 &prm->
ptype, &prmtypmod,
6437 Datum *resv,
bool *resnull)
6451 Assert(dno >= 0 && dno < estate->ndatums);
6454 datum = estate->
datums[dno];
6477 bool isvarlena = (((
PLpgSQL_var *) datum)->datatype->typlen == -1);
6490 if (((
PLpgSQL_var *) datum)->datatype->typlen == -1)
6540 Assert(dno >= 0 && dno < estate->ndatums);
6637 Assert(dno >= 0 && dno < estate->ndatums);
6693 Assert(dno >= 0 && dno < estate->ndatums);
6725 Assert(dno >= 0 && dno < estate->ndatums);
6764 Assert(dno >= 0 && dno < estate->ndatums);
6795 (
errcode(ERRCODE_UNDEFINED_COLUMN),
6796 errmsg(
"record \"%s\" has no field \"%s\"",
6809 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6810 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6836 Assert(dno >= 0 && dno < estate->ndatums);
6839 datum = estate->
datums[dno];
6843 &datumtype, &datumtypmod,
6849 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6850 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6876 Assert(dno >= 0 && dno < estate->ndatums);
6879 datum = estate->
datums[dno];
6883 &datumtype, &datumtypmod,
6889 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6890 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6932 if (tupdesc == NULL)
7003 int td_natts = tupdesc->
natts;
7006 Datum values_local[64];
7007 bool nulls_local[64];
7014 if (td_natts <=
lengthof(values_local))
7017 nulls = nulls_local;
7024 td_natts * (
sizeof(
Datum) +
sizeof(
bool)));
7026 nulls = (
bool *) (chunk + td_natts *
sizeof(
Datum));
7086 if (typentry->
typtype == TYPTYPE_DOMAIN)
7089 if (typentry->
tupDesc == NULL)
7096 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7097 errmsg(
"type %s is not composite",
7197 int td_natts = tupdesc ? tupdesc->
natts : 0;
7200 int strict_multiassignment_level = 0;
7206 if (tupdesc != NULL)
7209 strict_multiassignment_level =
ERROR;
7211 strict_multiassignment_level =
WARNING;
7219 Datum newvalues_local[64];
7220 bool newnulls_local[64];
7235 if (var_tupdesc != tupdesc)
7237 int vtd_natts = var_tupdesc->
natts;
7246 if (vtd_natts <=
lengthof(newvalues_local))
7248 newvalues = newvalues_local;
7249 newnulls = newnulls_local;
7256 vtd_natts * (
sizeof(
Datum) +
sizeof(
bool)));
7257 newvalues = (
Datum *) chunk;
7258 newnulls = (
bool *) (chunk + vtd_natts *
sizeof(
Datum));
7263 for (fnum = 0; fnum < vtd_natts; fnum++)
7271 if (attr->attisdropped)
7277 while (anum < td_natts &&
7281 if (anum < td_natts)
7284 isnull = nulls[anum];
7294 valtype = UNKNOWNOID;
7298 if (strict_multiassignment_level)
7299 ereport(strict_multiassignment_level,
7300 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7301 errmsg(
"number of source and target fields in assignment does not match"),
7304 "strict_multi_assignment",
7305 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7307 errhint(
"Make sure the query returns the exact list of columns.")));
7318 newnulls[fnum] = isnull;
7325 if (strict_multiassignment_level && anum < td_natts)
7328 while (anum < td_natts &&
7332 if (anum < td_natts)
7333 ereport(strict_multiassignment_level,
7334 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7335 errmsg(
"number of source and target fields in assignment does not match"),
7338 "strict_multi_assignment",
7339 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7341 errhint(
"Make sure the query returns the exact list of columns.")));
7376 for (fnum = 0; fnum < row->
nfields; fnum++)
7386 while (anum < td_natts &&
7390 if (anum < td_natts)
7393 isnull = nulls[anum];
7403 valtype = UNKNOWNOID;
7406 if (strict_multiassignment_level)
7407 ereport(strict_multiassignment_level,
7408 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7409 errmsg(
"number of source and target fields in assignment does not match"),
7412 "strict_multi_assignment",
7413 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7415 errhint(
"Make sure the query returns the exact list of columns.")));
7419 value, isnull, valtype, valtypmod);
7426 if (strict_multiassignment_level && anum < td_natts)
7428 while (anum < td_natts &&
7432 if (anum < td_natts)
7433 ereport(strict_multiassignment_level,
7434 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7435 errmsg(
"number of source and target fields in assignment does not match"),
7438 "strict_multi_assignment",
7439 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7441 errhint(
"Make sure the query returns the exact list of columns.")));
7462 if (dst_tupdesc->
natts != src_tupdesc->
natts)
7465 for (
i = 0;
i < dst_tupdesc->
natts;
i++)
7470 if (dattr->attisdropped != sattr->attisdropped)
7472 if (!dattr->attisdropped)
7475 if (dattr->atttypid != sattr->atttypid ||
7476 (dattr->atttypmod >= 0 &&
7477 dattr->atttypmod != sattr->atttypmod))
7483 if (dattr->attlen != sattr->attlen ||
7484 dattr->attalign != sattr->attalign)
7505 int natts = tupdesc->
natts;
7517 for (
i = 0;
i < natts;
i++)
7529 &fieldtypeid, &fieldtypmod,
7530 &dvalues[
i], &nulls[
i]);
7611 if (erh == rec->
erh)
7765 (tupType != RECORDOID ||
7827 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
7829 errdetail(
"The tuple structure of a not-yet-assigned record is indeterminate.")));
7892 if (valtype != reqtype ||
7893 (valtypmod != reqtypmod && reqtypmod != -1))
7897 reqtype, reqtypmod);
7917 reqtype, reqtypmod);
8024 placeholder->
typeId = srctype;
8025 placeholder->typeMod = srctypmod;
8043 if (srctype == UNKNOWNOID || srctype == RECORDOID)
8047 (
Node *) placeholder, srctype,
8060 if (cast_expr == NULL)
8064 iocoerce->
arg = (
Expr *) placeholder;
8069 cast_expr = (
Node *) iocoerce;
8070 if (dsttypmod != -1)
8083 cast_expr = cast_cexpr->
expr;
8252 if (query->hasAggs ||
8253 query->hasWindowFuncs ||
8254 query->hasTargetSRFs ||
8255 query->hasSubLinks ||
8321 plan->righttree == NULL &&
8322 plan->initPlan == NULL &&
8323 plan->qual == NULL &&
8330 plan->righttree == NULL &&
8331 plan->initPlan == NULL &&
8332 plan->qual == NULL);
8343 elog(
ERROR,
"unexpected plan node type: %d",
8448 if (context.
count == 1)
8472 fargs = fexpr->
args;
8478 funcid = opexpr->opfuncid;
8479 fargs = opexpr->
args;
8509 req.
type = T_SupportRequestModifyInPlace;
8553 if (++(context->
count) > 1)
8572 Assert(dno >= 0 && dno < estate->ndatums);
8573 datum = estate->
datums[dno];
8574 switch (datum->
dtype)
8581 (
errcode(ERRCODE_ERROR_IN_ASSIGNMENT),
8582 errmsg(
"variable \"%s\" is declared CONSTANT",
8658 "PL/pgSQL simple expressions");
8781 Datum newvalue,
bool isnull,
bool freeable)
8815 newvalue =
datumCopy(detoasted,
false, -1);
8831 var->
value = newvalue;
8918 if (prm->
ptype == UNKNOWNOID)
8927 prm->
ptype = TEXTOID;
8964 const char *portalname,
8980 query =
exec_eval_expr(estate, dynquery, &isnull, &restype, &restypmod);
8983 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
8984 errmsg(
"query string argument of EXECUTE is null")));
9001 options.cursorOptions = cursorOptions;
9007 elog(
ERROR,
"could not open implicit cursor for query \"%s\": %s",
9049 ¶mtypeid, ¶mtypmod,
9050 ¶mdatum, ¶misnull);
9053 paramno > 0 ?
", " :
"",
9070 return paramstr.
data;
9092 for (paramno = 0; paramno < paramLI->
numParams; paramno++)
9102 paramno > 0 ?
", " :
"",
9117 return paramstr.
data;
static bool array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
#define DatumGetArrayTypePCopy(X)
Datum expand_array(Datum arraydatum, MemoryContext parentcontext, ArrayMetaState *metacache)
bool array_iterate(ArrayIterator iterator, Datum *value, bool *isnull)
ArrayIterator array_create_iterator(ArrayType *arr, int slice_ndim, ArrayMetaState *mstate)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_member(int x, const Bitmapset *a)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
uint32 LocalTransactionId
#define OidIsValid(objectId)
bool contain_mutable_functions(Node *clause)
const char * GetCommandTagName(CommandTag commandTag)
Datum datumCopy(Datum value, bool typByVal, int typLen)
Datum datumTransfer(Datum value, bool typByVal, int typLen)
DestReceiver * CreateDestReceiver(CommandDest dest)
struct varlena * detoast_external_attr(struct varlena *attr)
void domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int err_generic_string(int field, const char *str)
int errmsg_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errmsg_internal(const char *fmt,...)
char * GetErrorContextStack(void)
int errdetail_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
void ReThrowError(ErrorData *edata)
ErrorData * CopyErrorData(void)
void FlushErrorState(void)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
char * unpack_sql_state(int sql_state)
#define ERRCODE_IS_CATEGORY(ec)
#define ERRCODE_TO_CATEGORY(ec)
#define ereport(elevel,...)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
void ExprEvalPushStep(ExprState *es, const ExprEvalStep *s)
ExprState * ExecInitExprWithParams(Expr *node, ParamListInfo ext_params)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
ExprContext * CreateExprContext(EState *estate)
void FreeExprContext(ExprContext *econtext, bool isCommit)
void FreeExecutorState(EState *estate)
EState * CreateExecutorState(void)
@ SFRM_Materialize_Random
#define ResetExprContext(econtext)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
ExpandedObjectHeader * DatumGetEOHP(Datum d)
void EOH_flatten_into(ExpandedObjectHeader *eohptr, void *result, Size allocated_size)
void DeleteExpandedObject(Datum d)
Datum TransferExpandedObject(Datum d, MemoryContext new_parent)
Size EOH_get_flat_size(ExpandedObjectHeader *eohptr)
#define MakeExpandedObjectReadOnly(d, isnull, typlen)
#define DatumIsReadWriteExpandedObject(d, isnull, typlen)
ExpandedRecordHeader * make_expanded_record_from_exprecord(ExpandedRecordHeader *olderh, MemoryContext parentcontext)
ExpandedRecordHeader * make_expanded_record_from_tupdesc(TupleDesc tupdesc, MemoryContext parentcontext)
void expanded_record_set_field_internal(ExpandedRecordHeader *erh, int fnumber, Datum newValue, bool isnull, bool expand_external, bool check_constraints)
bool expanded_record_lookup_field(ExpandedRecordHeader *erh, const char *fieldname, ExpandedRecordFieldInfo *finfo)
ExpandedRecordHeader * make_expanded_record_from_typeid(Oid type_id, int32 typmod, MemoryContext parentcontext)
void expanded_record_set_tuple(ExpandedRecordHeader *erh, HeapTuple tuple, bool copy, bool expand_external)
HeapTuple expanded_record_get_tuple(ExpandedRecordHeader *erh)
void deconstruct_expanded_record(ExpandedRecordHeader *erh)
void expanded_record_set_fields(ExpandedRecordHeader *erh, const Datum *newValues, const bool *isnulls, bool expand_external)
#define expanded_record_set_field(erh, fnumber, newValue, isnull, expand_external)
#define ExpandedRecordIsEmpty(erh)
static Datum ExpandedRecordGetDatum(const ExpandedRecordHeader *erh)
static Datum expanded_record_get_field(ExpandedRecordHeader *erh, int fnumber, bool *isnull)
#define ExpandedRecordIsDomain(erh)
static TupleDesc expanded_record_get_tupdesc(ExpandedRecordHeader *erh)
#define ER_FLAG_FVALUE_VALID
#define TransferExpandedRecord(erh, cxt)
char * OidOutputFunctionCall(Oid functionId, Datum val)
#define OidFunctionCall1(functionId, arg1)
#define DatumGetHeapTupleHeader(X)
#define DirectFunctionCall1(func, arg1)
int get_func_arg_info(HeapTuple procTup, Oid **p_argtypes, char ***p_argnames, char **p_argmodes)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
@ TYPEFUNC_COMPOSITE_DOMAIN
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Assert(PointerIsAligned(start, uint64))
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
HeapTupleHeaderData * HeapTupleHeader
#define HeapTupleIsValid(tuple)
static void HeapTupleHeaderSetTypMod(HeapTupleHeaderData *tup, int32 typmod)
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
static void HeapTupleHeaderSetTypeId(HeapTupleHeaderData *tup, Oid datum_typeid)
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
if(TABLE==NULL||TABLE_index==NULL)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
#define InvalidLocalTransactionId
Oid get_element_type(Oid typid)
bool type_is_rowtype(Oid typid)
RegProcedure get_func_support(Oid funcid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Oid get_typcollation(Oid typid)
char * get_namespace_name(Oid nspid)
RegProcedure get_typsubscript(Oid typid, Oid *typelemp)
char * MemoryContextStrdup(MemoryContext context, const char *string)
void * MemoryContextAlloc(MemoryContext context, Size size)
void MemoryContextReset(MemoryContext context)
MemoryContext TopTransactionContext
void pfree(void *pointer)
void * palloc0(Size size)
void MemoryContextDeleteChildren(MemoryContext context)
MemoryContext CurrentMemoryContext
MemoryContext MemoryContextGetParent(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CHECK_FOR_INTERRUPTS()
Datum namein(PG_FUNCTION_ARGS)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
#define expression_tree_walker(n, w, c)
#define IsA(nodeptr, _type_)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
ParamListInfo makeParamList(int numParams)
void(* ParserSetupHook)(struct ParseState *pstate, void *arg)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
void typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName, Oid *typeid_p, int32 *typmod_p)
#define CURSOR_OPT_PARALLEL_OK
#define CURSOR_OPT_NO_SCROLL
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
#define linitial_node(type, l)
static void * list_nth(const List *list, int n)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
void plpgsql_parser_setup(struct ParseState *pstate, PLpgSQL_expr *expr)
int plpgsql_recognize_err_condition(const char *condname, bool allow_sqlstate)
PLpgSQL_type * plpgsql_build_datatype(Oid typeOid, int32 typmod, Oid collation, TypeName *origtypname)
static void coerce_function_result_tuple(PLpgSQL_execstate *estate, TupleDesc tupdesc)
struct SimpleEcontextStackEntry SimpleEcontextStackEntry
static void exec_simple_check_plan(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
static int exec_stmt_fors(PLpgSQL_execstate *estate, PLpgSQL_stmt_fors *stmt)
static int exec_stmt_fetch(PLpgSQL_execstate *estate, PLpgSQL_stmt_fetch *stmt)
#define eval_mcontext_alloc(estate, sz)
static void plpgsql_fulfill_promise(PLpgSQL_execstate *estate, PLpgSQL_var *var)
static ParamExternData * plpgsql_param_fetch(ParamListInfo params, int paramid, bool speculative, ParamExternData *prm)
static void exec_init_tuple_store(PLpgSQL_execstate *estate)
static void plpgsql_param_eval_var_ro(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static int exec_for_query(PLpgSQL_execstate *estate, PLpgSQL_stmt_forq *stmt, Portal portal, bool prefetch_ok)
static ResourceOwner shared_simple_eval_resowner
static int exec_stmt_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
static int exec_stmt_commit(PLpgSQL_execstate *estate, PLpgSQL_stmt_commit *stmt)
static void plpgsql_create_econtext(PLpgSQL_execstate *estate)
#define get_eval_mcontext(estate)
static void assign_record_var(PLpgSQL_execstate *estate, PLpgSQL_rec *rec, ExpandedRecordHeader *erh)
static int exec_eval_integer(PLpgSQL_execstate *estate, PLpgSQL_expr *expr, bool *isNull)
static int exec_stmt_forc(PLpgSQL_execstate *estate, PLpgSQL_stmt_forc *stmt)
#define SET_RAISE_OPTION_TEXT(opt, name)
static int exec_stmt_execsql(PLpgSQL_execstate *estate, PLpgSQL_stmt_execsql *stmt)
static char * format_expr_params(PLpgSQL_execstate *estate, const PLpgSQL_expr *expr)
static void exec_eval_cleanup(PLpgSQL_execstate *estate)
static int exec_stmt_foreach_a(PLpgSQL_execstate *estate, PLpgSQL_stmt_foreach_a *stmt)
static int exec_stmt_rollback(PLpgSQL_execstate *estate, PLpgSQL_stmt_rollback *stmt)
Datum plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo, EState *simple_eval_estate, ResourceOwner simple_eval_resowner, ResourceOwner procedure_resowner, bool atomic)
static EState * shared_simple_eval_estate
static void revalidate_rectypeid(PLpgSQL_rec *rec)
static HTAB * shared_cast_hash
static void plpgsql_exec_error_callback(void *arg)
static void plpgsql_estate_setup(PLpgSQL_execstate *estate, PLpgSQL_function *func, ReturnSetInfo *rsi, EState *simple_eval_estate, ResourceOwner simple_eval_resowner)
static void plpgsql_param_compile(ParamListInfo params, Param *param, ExprState *state, Datum *resv, bool *resnull)
#define LOOP_RC_PROCESSING(looplabel, exit_action)
static void exec_move_row_from_datum(PLpgSQL_execstate *estate, PLpgSQL_variable *target, Datum value)
static void exec_assign_value(PLpgSQL_execstate *estate, PLpgSQL_datum *target, Datum value, bool isNull, Oid valtype, int32 valtypmod)
static bool exception_matches_conditions(ErrorData *edata, PLpgSQL_condition *cond)
static void exec_move_row_from_fields(PLpgSQL_execstate *estate, PLpgSQL_variable *target, ExpandedRecordHeader *newerh, Datum *values, bool *nulls, TupleDesc tupdesc)
static void exec_prepare_plan(PLpgSQL_execstate *estate, PLpgSQL_expr *expr, int cursorOptions)
static void exec_eval_datum(PLpgSQL_execstate *estate, PLpgSQL_datum *datum, Oid *typeid, int32 *typetypmod, Datum *value, bool *isnull)
static int exec_stmt_return(PLpgSQL_execstate *estate, PLpgSQL_stmt_return *stmt)
static void plpgsql_param_eval_recfield(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static void plpgsql_param_eval_generic_ro(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static int exec_stmt_exit(PLpgSQL_execstate *estate, PLpgSQL_stmt_exit *stmt)
static void instantiate_empty_record_variable(PLpgSQL_execstate *estate, PLpgSQL_rec *rec)
void plpgsql_exec_get_datum_type_info(PLpgSQL_execstate *estate, PLpgSQL_datum *datum, Oid *typeId, int32 *typMod, Oid *collation)
static TupleDesc deconstruct_composite_datum(Datum value, HeapTupleData *tmptup)
static plpgsql_CastHashEntry * get_cast_hashentry(PLpgSQL_execstate *estate, Oid srctype, int32 srctypmod, Oid dsttype, int32 dsttypmod)
static int exec_stmt_raise(PLpgSQL_execstate *estate, PLpgSQL_stmt_raise *stmt)
static char * convert_value_to_string(PLpgSQL_execstate *estate, Datum value, Oid valtype)
static Datum do_cast_value(PLpgSQL_execstate *estate, Datum value, bool *isnull, Oid valtype, int32 valtypmod, Oid reqtype, int32 reqtypmod)
struct count_param_references_context count_param_references_context
static Datum exec_cast_value(PLpgSQL_execstate *estate, Datum value, bool *isnull, Oid valtype, int32 valtypmod, Oid reqtype, int32 reqtypmod)
static ParamListInfo setup_param_list(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
static int exec_stmts(PLpgSQL_execstate *estate, List *stmts)
static int exec_stmt_loop(PLpgSQL_execstate *estate, PLpgSQL_stmt_loop *stmt)
static void assign_text_var(PLpgSQL_execstate *estate, PLpgSQL_var *var, const char *str)
static void exec_assign_c_string(PLpgSQL_execstate *estate, PLpgSQL_datum *target, const char *str)
static int exec_stmt_open(PLpgSQL_execstate *estate, PLpgSQL_stmt_open *stmt)
static void exec_set_found(PLpgSQL_execstate *estate, bool state)
static int exec_stmt_dynexecute(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynexecute *stmt)
static bool compatible_tupdescs(TupleDesc src_tupdesc, TupleDesc dst_tupdesc)
static SimpleEcontextStackEntry * simple_econtext_stack
static void exec_save_simple_expr(PLpgSQL_expr *expr, CachedPlan *cplan)
static void plpgsql_param_eval_generic(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static void exec_assign_expr(PLpgSQL_execstate *estate, PLpgSQL_datum *target, PLpgSQL_expr *expr)
static HTAB * cast_expr_hash
static void assign_simple_var(PLpgSQL_execstate *estate, PLpgSQL_var *var, Datum newvalue, bool isnull, bool freeable)
static int exec_stmt_assert(PLpgSQL_execstate *estate, PLpgSQL_stmt_assert *stmt)
static int exec_stmt_return_query(PLpgSQL_execstate *estate, PLpgSQL_stmt_return_query *stmt)
static void exec_move_row(PLpgSQL_execstate *estate, PLpgSQL_variable *target, HeapTuple tup, TupleDesc tupdesc)
static MemoryContext get_stmt_mcontext(PLpgSQL_execstate *estate)
static int exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt)
static ExpandedRecordHeader * make_expanded_record_for_rec(PLpgSQL_execstate *estate, PLpgSQL_rec *rec, TupleDesc srctupdesc, ExpandedRecordHeader *srcerh)
static int exec_stmt_fori(PLpgSQL_execstate *estate, PLpgSQL_stmt_fori *stmt)
static int exec_stmt_if(PLpgSQL_execstate *estate, PLpgSQL_stmt_if *stmt)
static int exec_toplevel_block(PLpgSQL_execstate *estate, PLpgSQL_stmt_block *block)
static int exec_stmt_case(PLpgSQL_execstate *estate, PLpgSQL_stmt_case *stmt)
static int exec_stmt_return_next(PLpgSQL_execstate *estate, PLpgSQL_stmt_return_next *stmt)
static void plpgsql_destroy_econtext(PLpgSQL_execstate *estate)
static int exec_stmt_assign(PLpgSQL_execstate *estate, PLpgSQL_stmt_assign *stmt)
HeapTuple plpgsql_exec_trigger(PLpgSQL_function *func, TriggerData *trigdata)
static int exec_stmt_dynfors(PLpgSQL_execstate *estate, PLpgSQL_stmt_dynfors *stmt)
#define eval_mcontext_alloc0(estate, sz)
static ParamListInfo exec_eval_using_params(PLpgSQL_execstate *estate, List *params)
static Portal exec_dynquery_with_params(PLpgSQL_execstate *estate, PLpgSQL_expr *dynquery, List *params, const char *portalname, int cursorOptions)
static int exec_stmt_getdiag(PLpgSQL_execstate *estate, PLpgSQL_stmt_getdiag *stmt)
static bool exec_eval_boolean(PLpgSQL_execstate *estate, PLpgSQL_expr *expr, bool *isNull)
static void plpgsql_param_eval_var_transfer(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
static void plpgsql_param_eval_var(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static void plpgsql_param_eval_var_check(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
void plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
static void push_stmt_mcontext(PLpgSQL_execstate *estate)
static Datum exec_eval_expr(PLpgSQL_execstate *estate, PLpgSQL_expr *expr, bool *isNull, Oid *rettype, int32 *rettypmod)
static int exec_stmt_while(PLpgSQL_execstate *estate, PLpgSQL_stmt_while *stmt)
static void pop_stmt_mcontext(PLpgSQL_execstate *estate)
static void exec_check_assignable(PLpgSQL_execstate *estate, int dno)
static char * format_preparedparamsdata(PLpgSQL_execstate *estate, ParamListInfo paramLI)
static bool count_param_references(Node *node, count_param_references_context *context)
static PLpgSQL_variable * make_callstmt_target(PLpgSQL_execstate *estate, PLpgSQL_expr *expr)
static HeapTuple make_tuple_from_row(PLpgSQL_execstate *estate, PLpgSQL_row *row, TupleDesc tupdesc)
static int exec_stmt_perform(PLpgSQL_execstate *estate, PLpgSQL_stmt_perform *stmt)
static bool exec_is_simple_query(PLpgSQL_expr *expr)
static void exec_check_rw_parameter(PLpgSQL_expr *expr, int paramid)
void plpgsql_xact_cb(XactEvent event, void *arg)
static bool exec_eval_simple_expr(PLpgSQL_execstate *estate, PLpgSQL_expr *expr, Datum *result, bool *isNull, Oid *rettype, int32 *rettypmod)
static void copy_plpgsql_datums(PLpgSQL_execstate *estate, PLpgSQL_function *func)
static int exec_run_select(PLpgSQL_execstate *estate, PLpgSQL_expr *expr, long maxtuples, Portal *portalP)
static int exec_stmt_close(PLpgSQL_execstate *estate, PLpgSQL_stmt_close *stmt)
Oid plpgsql_exec_get_datum_type(PLpgSQL_execstate *estate, PLpgSQL_datum *datum)
const char * plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
bool plpgsql_check_asserts
int plpgsql_extra_warnings
PLpgSQL_plugin ** plpgsql_plugin_ptr
bool CachedPlanAllowsSimpleValidityCheck(CachedPlanSource *plansource, CachedPlan *plan, ResourceOwner owner)
void FreeCachedExpression(CachedExpression *cexpr)
CachedExpression * GetCachedExpression(Node *expr)
bool CachedPlanIsSimplyValid(CachedPlanSource *plansource, CachedPlan *plan, ResourceOwner owner)
void ReleaseCachedPlan(CachedPlan *plan, ResourceOwner owner)
void ReleaseAllPlanCacheRefsInOwner(ResourceOwner owner)
@ PLPGSQL_STMT_RETURN_QUERY
@ PLPGSQL_STMT_RETURN_NEXT
@ PLPGSQL_STMT_DYNEXECUTE
#define PLPGSQL_XCHECK_TOOMANYROWS
@ PLPGSQL_RAISEOPTION_COLUMN
@ PLPGSQL_RAISEOPTION_TABLE
@ PLPGSQL_RAISEOPTION_SCHEMA
@ PLPGSQL_RAISEOPTION_CONSTRAINT
@ PLPGSQL_RAISEOPTION_DETAIL
@ PLPGSQL_RAISEOPTION_MESSAGE
@ PLPGSQL_RAISEOPTION_HINT
@ PLPGSQL_RAISEOPTION_ERRCODE
@ PLPGSQL_RAISEOPTION_DATATYPE
#define PLPGSQL_XCHECK_STRICTMULTIASSIGNMENT
@ PLPGSQL_PROMISE_TG_RELID
@ PLPGSQL_PROMISE_TG_WHEN
@ PLPGSQL_PROMISE_TG_ARGV
@ PLPGSQL_PROMISE_TG_TABLE_SCHEMA
@ PLPGSQL_PROMISE_TG_EVENT
@ PLPGSQL_PROMISE_TG_TABLE_NAME
@ PLPGSQL_PROMISE_TG_LEVEL
@ PLPGSQL_PROMISE_TG_NARGS
@ PLPGSQL_PROMISE_TG_NAME
@ PLPGSQL_GETDIAG_ERROR_DETAIL
@ PLPGSQL_GETDIAG_SCHEMA_NAME
@ PLPGSQL_GETDIAG_MESSAGE_TEXT
@ PLPGSQL_GETDIAG_DATATYPE_NAME
@ PLPGSQL_GETDIAG_TABLE_NAME
@ PLPGSQL_GETDIAG_CONSTRAINT_NAME
@ PLPGSQL_GETDIAG_COLUMN_NAME
@ PLPGSQL_GETDIAG_ROW_COUNT
@ PLPGSQL_GETDIAG_RETURNED_SQLSTATE
@ PLPGSQL_GETDIAG_CONTEXT
@ PLPGSQL_GETDIAG_ERROR_HINT
@ PLPGSQL_GETDIAG_ERROR_CONTEXT
@ PLPGSQL_GETDIAG_ROUTINE_OID
void PinPortal(Portal portal)
void UnpinPortal(Portal portal)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum UInt64GetDatum(uint64 X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static char * DatumGetCString(Datum X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
#define PG_DIAG_SCHEMA_NAME
#define PG_DIAG_CONSTRAINT_NAME
#define PG_DIAG_DATATYPE_NAME
#define PG_DIAG_TABLE_NAME
#define PG_DIAG_COLUMN_NAME
void EnsurePortalSnapshotExists(void)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
ResourceOwner TopTransactionResourceOwner
ResourceOwner ResourceOwnerCreate(ResourceOwner parent, const char *name)
ResourceOwner CurrentResourceOwner
Snapshot GetTransactionSnapshot(void)
void PushActiveSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
List * SPI_plan_get_plan_sources(SPIPlanPtr plan)
int SPI_execute_plan_with_paramlist(SPIPlanPtr plan, ParamListInfo params, bool read_only, long tcount)
void SPI_scroll_cursor_move(Portal portal, FetchDirection direction, long count)
void SPI_commit_and_chain(void)
SPIPlanPtr SPI_prepare_extended(const char *src, const SPIPrepareOptions *options)
HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc)
const char * SPI_result_code_string(int code)
void SPI_rollback_and_chain(void)
SPITupleTable * SPI_tuptable
Portal SPI_cursor_find(const char *name)
int SPI_execute_plan_extended(SPIPlanPtr plan, const SPIExecuteOptions *options)
void SPI_cursor_fetch(Portal portal, bool forward, long count)
Portal SPI_cursor_parse_open(const char *name, const char *src, const SPIParseOpenOptions *options)
Datum SPI_datumTransfer(Datum value, bool typByVal, int typLen)
CachedPlan * SPI_plan_get_cached_plan(SPIPlanPtr plan)
int SPI_register_trigger_data(TriggerData *tdata)
Portal SPI_cursor_open_with_paramlist(const char *name, SPIPlanPtr plan, ParamListInfo params, bool read_only)
void SPI_freetuptable(SPITupleTable *tuptable)
int SPI_keepplan(SPIPlanPtr plan)
void SPI_cursor_close(Portal portal)
void SPI_scroll_cursor_fetch(Portal portal, FetchDirection direction, long count)
int SPI_execute_extended(const char *src, const SPIExecuteOptions *options)
void * SPI_palloc(Size size)
HeapTuple SPI_copytuple(HeapTuple tuple)
Datum SPI_getbinval(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool *isnull)
#define SPI_ERROR_TRANSACTION
#define SPI_OK_UPDATE_RETURNING
#define SPI_OK_INSERT_RETURNING
#define SPI_OK_DELETE_RETURNING
#define SPI_OK_MERGE_RETURNING
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
void appendStringInfoStringQuoted(StringInfo str, const char *s, int maxlen)
MemoryContext es_query_cxt
struct ErrorContextCallback * previous
void(* callback)(void *arg)
ParamListInfo ecxt_param_list_info
MemoryContext ecxt_per_query_memory
struct ExprEvalStep::@55::@69 cparam
ExecEvalSubroutine paramfunc
union ExprEvalStep::@55 d
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
struct PLpgSQL_condition * next
PLpgSQL_getdiag_kind kind
PLpgSQL_condition * conditions
EState * simple_eval_estate
ResourceOwner simple_eval_resowner
ExprContext * eval_econtext
ResourceOwner procedure_resowner
Tuplestorestate * tuple_store
PLpgSQL_variable * err_var
MemoryContext tuple_store_cxt
TupleDesc tuple_store_desc
MemoryContext datum_context
MemoryContext stmt_mcontext
SPITupleTable * eval_tuptable
EventTriggerData * evtrigdata
ResourceOwner tuple_store_owner
MemoryContext stmt_mcontext_parent
CachedPlanSource * expr_simple_plansource
CachedPlan * expr_simple_plan
ExprState * expr_simple_state
LocalTransactionId expr_simple_plan_lxid
LocalTransactionId expr_simple_lxid
int fn_argvarnos[FUNC_MAX_ARGS]
PLpgSQL_stmt_block * action
struct PLpgSQL_execstate * cur_estate
void(* stmt_end)(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
void(* func_beg)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
void(* func_end)(PLpgSQL_execstate *estate, PLpgSQL_function *func)
void(* stmt_beg)(PLpgSQL_execstate *estate, PLpgSQL_stmt *stmt)
PLpgSQL_raise_option_type opt_type
ExpandedRecordHeader * erh
PLpgSQL_expr * default_val
ExpandedRecordFieldInfo finfo
PLpgSQL_exception_block * exceptions
PLpgSQL_variable * target
PLpgSQL_stmt_type cmd_type
PLpgSQL_promise_type promise
int cursor_explicit_argrow
PLpgSQL_expr * cursor_explicit_expr
PLpgSQL_expr * default_val
ParamExternData params[FLEXIBLE_ARRAY_MEMBER]
ParserSetupHook parserSetup
ParamCompileHook paramCompile
ParamFetchHook paramFetch
SetFunctionReturnMode returnMode
Tuplestorestate * setResult
struct SimpleEcontextStackEntry * next
ExprContext * stack_econtext
SubTransactionId xact_subxid
bool has_generated_stored
uint64 tupDesc_identifier
void(* rDestroy)(DestReceiver *self)
CachedExpression * cast_cexpr
LocalTransactionId cast_lxid
ExprState * cast_exprstate
plpgsql_CastExprHashEntry * cast_centry
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define TRIGGER_FIRED_FOR_STATEMENT(event)
#define TRIGGER_FIRED_BY_DELETE(event)
#define TRIGGER_FIRED_BEFORE(event)
#define TRIGGER_FIRED_FOR_ROW(event)
#define TRIGGER_FIRED_AFTER(event)
#define TRIGGER_FIRED_BY_TRUNCATE(event)
#define TRIGGER_FIRED_BY_INSERT(event)
#define TRIGGER_FIRED_BY_UPDATE(event)
#define TRIGGER_FIRED_INSTEAD(event)
void SetTuplestoreDestReceiverParams(DestReceiver *self, Tuplestorestate *tStore, MemoryContext tContext, bool detoast, TupleDesc target_tupdesc, const char *map_failure_msg)
TupleConversionMap * convert_tuples_by_position(TupleDesc indesc, TupleDesc outdesc, const char *msg)
HeapTuple execute_attr_map_tuple(HeapTuple tuple, TupleConversionMap *map)
TupleDesc CreateTupleDescCopy(TupleDesc tupdesc)
#define ReleaseTupleDesc(tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
int64 tuplestore_tuple_count(Tuplestorestate *state)
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_puttuple(Tuplestorestate *state, HeapTuple tuple)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define INVALID_TUPLEDESC_IDENTIFIER
#define TYPECACHE_TUPDESC
#define TYPECACHE_DOMAIN_BASE_INFO
#define VARATT_IS_EXTERNAL_EXPANDED_RO(PTR)
#define VARATT_IS_EXTERNAL_EXPANDED(PTR)
#define VARATT_IS_EXTERNAL_EXPANDED_RW(PTR)
#define VARATT_IS_EXTERNAL_NON_EXPANDED(PTR)
text * cstring_to_text(const char *s)
void BeginInternalSubTransaction(const char *name)
SubTransactionId GetCurrentSubTransactionId(void)
void CommandCounterIncrement(void)
void RollbackAndReleaseCurrentSubTransaction(void)
void ReleaseCurrentSubTransaction(void)
@ SUBXACT_EVENT_ABORT_SUB
@ SUBXACT_EVENT_COMMIT_SUB
@ XACT_EVENT_PARALLEL_COMMIT
@ XACT_EVENT_PARALLEL_ABORT