42#include "utils/fmgroids.h"
126#define get_eval_mcontext(estate) \
127 ((estate)->eval_econtext->ecxt_per_tuple_memory)
128#define eval_mcontext_alloc(estate, sz) \
129 MemoryContextAlloc(get_eval_mcontext(estate), sz)
130#define eval_mcontext_alloc0(estate, sz) \
131 MemoryContextAllocZero(get_eval_mcontext(estate), sz)
203#define LOOP_RC_PROCESSING(looplabel, exit_action) \
204 if (rc == PLPGSQL_RC_RETURN) \
209 else if (rc == PLPGSQL_RC_EXIT) \
211 if (estate->exitlabel == NULL) \
214 rc = PLPGSQL_RC_OK; \
217 else if ((looplabel) != NULL && \
218 strcmp(looplabel, estate->exitlabel) == 0) \
221 estate->exitlabel = NULL; \
222 rc = PLPGSQL_RC_OK; \
231 else if (rc == PLPGSQL_RC_CONTINUE) \
233 if (estate->exitlabel == NULL) \
236 rc = PLPGSQL_RC_OK; \
238 else if ((looplabel) != NULL && \
239 strcmp(looplabel, estate->exitlabel) == 0) \
242 estate->exitlabel = NULL; \
243 rc = PLPGSQL_RC_OK; \
252 Assert(rc == PLPGSQL_RC_OK)
330 EState *simple_eval_estate,
378 Portal portal,
bool prefetch_ok);
382 int paramid,
bool speculative,
386 Datum *resv,
bool *resnull);
439 Datum newvalue,
bool isnull,
bool freeable);
448 const char *portalname,
int cursorOptions);
478 EState *simple_eval_estate,
492 simple_eval_estate, simple_eval_resowner);
500 plerrcontext.
arg = &estate;
613 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
624 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
625 errmsg(
"control reached end of function without RETURN")));
642 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
643 errmsg(
"set-valued function called in context that cannot accept a set")));
647 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
648 errmsg(
"materialize mode required, but it is not allowed in this context")));
730 elog(
ERROR,
"return type must be a row type");
781 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
830 gettext_noop(
"returned record type does not match expected record type"));
894 gettext_noop(
"returned record type does not match expected record type"));
940 plerrcontext.
arg = &estate;
999 for (
int i = 0;
i < tupdesc->
natts;
i++)
1000 if (
TupleDescAttr(tupdesc,
i)->attgenerated == ATTRIBUTE_GENERATED_STORED)
1014 elog(
ERROR,
"unrecognized trigger action: not INSERT, DELETE, or UPDATE");
1031 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
1042 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
1043 errmsg(
"control reached end of trigger procedure without RETURN")));
1050 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1051 errmsg(
"trigger procedure cannot return a set")));
1090 gettext_noop(
"returned row structure does not match the structure of the triggering table"));
1118 gettext_noop(
"returned row structure does not match the structure of the triggering table"));
1135 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
1175 plerrcontext.
arg = &estate;
1189 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
1200 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
1201 errmsg(
"control reached end of trigger procedure without RETURN")));
1210 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
1259 errcontext(
"PL/pgSQL function %s line %d %s",
1275 else if (estate->
err_stmt != NULL && err_lineno > 0)
1278 errcontext(
"PL/pgSQL function %s line %d at %s",
1297 int ndatums = estate->
ndatums;
1313 ws_next = workspace;
1317 outdatums = estate->
datums;
1318 for (
i = 0;
i < ndatums;
i++)
1324 switch (indatum->
dtype)
1356 outdatums[
i] = outdatum;
1389 elog(
ERROR,
"trigger promise is not in a trigger function");
1398 elog(
ERROR,
"trigger promise is not in a trigger function");
1406 elog(
ERROR,
"unrecognized trigger execution time: not BEFORE, AFTER, or INSTEAD OF");
1411 elog(
ERROR,
"trigger promise is not in a trigger function");
1417 elog(
ERROR,
"unrecognized trigger event type: not ROW or STATEMENT");
1422 elog(
ERROR,
"trigger promise is not in a trigger function");
1432 elog(
ERROR,
"unrecognized trigger action: not INSERT, DELETE, UPDATE, or TRUNCATE");
1437 elog(
ERROR,
"trigger promise is not in a trigger function");
1445 elog(
ERROR,
"trigger promise is not in a trigger function");
1454 elog(
ERROR,
"trigger promise is not in a trigger function");
1463 elog(
ERROR,
"trigger promise is not in a trigger function");
1471 elog(
ERROR,
"trigger promise is not in a trigger function");
1485 for (
i = 0;
i < nelems;
i++)
1494 -1,
false, TYPALIGN_INT)),
1505 elog(
ERROR,
"event trigger promise is not in an event trigger function");
1511 elog(
ERROR,
"event trigger promise is not in an event trigger function");
1534 "PLpgSQL per-statement data",
1581 for (; cond != NULL; cond = cond->
next)
1590 if (sqlerrstate == 0)
1592 if (edata->
sqlerrcode != ERRCODE_QUERY_CANCELED &&
1626 ((*plpgsql_plugin_ptr)->stmt_beg) (estate, (
PLpgSQL_stmt *) block);
1634 ((*plpgsql_plugin_ptr)->stmt_end) (estate, (
PLpgSQL_stmt *) block);
1649 volatile int rc = -1;
1674 switch (datum->
dtype)
1808 resTypByVal, resTypLen);
1959 if (block->
label == NULL)
2005 ((*plpgsql_plugin_ptr)->stmt_beg) (estate,
stmt);
2009 switch (
stmt->cmd_type)
2128 ((*plpgsql_plugin_ptr)->stmt_end) (estate,
stmt);
2193 if (expr->
plan == NULL)
2206 if (
stmt->is_call &&
stmt->target == NULL)
2223 options.allow_nonatomic =
true;
2229 elog(
ERROR,
"SPI_execute_plan_extended failed executing query \"%s\": %s",
2234 if (before_lxid != after_lxid)
2254 elog(
ERROR,
"DO statement returned a row");
2259 elog(
ERROR,
"procedure call returned more than one row");
2299 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2303 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2305 funcexpr =
stmt->funcexpr;
2310 elog(
ERROR,
"cache lookup failed for function %u",
2329 row->
refname =
"(unnamed row)";
2341 for (
i = 0;
i < numargs;
i++)
2344 (argmodes[
i] == PROARGMODE_INOUT ||
2345 argmodes[
i] == PROARGMODE_OUT))
2358 row->
varnos[nfields++] = dno;
2363 if (argnames && argnames[
i] && argnames[
i][0])
2365 (
errcode(ERRCODE_SYNTAX_ERROR),
2366 errmsg(
"procedure parameter \"%s\" is an output parameter but corresponding argument is not writable",
2370 (
errcode(ERRCODE_SYNTAX_ERROR),
2371 errmsg(
"procedure parameter %d is an output parameter but corresponding argument is not writable",
2406 (
errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER),
2407 errmsg(
"GET STACKED DIAGNOSTICS cannot be used outside an exception handler")));
2409 foreach(lc,
stmt->diag_items)
2414 switch (diag_item->
kind)
2419 false, INT8OID, -1);
2480 char *contextstackstr;
2493 elog(
ERROR,
"unrecognized diagnostic item kind: %d",
2518 if (!isnull &&
value)
2521 foreach(lc,
stmt->elsif_list)
2527 if (!isnull &&
value)
2546 if (
stmt->t_expr != NULL)
2554 &isnull, &t_typoid, &t_typmod);
2585 foreach(l,
stmt->case_when_list)
2592 if (!isnull &&
value)
2610 if (!
stmt->have_else)
2612 (
errcode(ERRCODE_CASE_NOT_FOUND),
2613 errmsg(
"case not found"),
2614 errhint(
"CASE statement is missing ELSE part.")));
2661 if (isnull || !
value)
2699 &isnull, &valtype, &valtypmod);
2706 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2707 errmsg(
"lower bound of FOR loop cannot be null")));
2715 &isnull, &valtype, &valtypmod);
2722 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2723 errmsg(
"upper bound of FOR loop cannot be null")));
2733 &isnull, &valtype, &valtypmod);
2740 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2741 errmsg(
"BY value of FOR loop cannot be null")));
2744 if (step_value <= 0)
2746 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2747 errmsg(
"BY value of FOR loop must be greater than zero")));
2762 if (loop_value < end_value)
2767 if (loop_value > end_value)
2793 loop_value -= step_value;
2799 loop_value += step_value;
2856 char *curname = NULL;
2880 (
errcode(ERRCODE_DUPLICATE_CURSOR),
2881 errmsg(
"cursor \"%s\" already in use", curname)));
2891 if (
stmt->argquery != NULL)
2903 (
errcode(ERRCODE_SYNTAX_ERROR),
2904 errmsg(
"arguments given for cursor without arguments")));
2906 memset(&set_args, 0,
sizeof(set_args));
2910 set_args.
into =
true;
2916 elog(
ERROR,
"open cursor failed during argument processing");
2922 (
errcode(ERRCODE_SYNTAX_ERROR),
2923 errmsg(
"arguments required for cursor")));
2929 if (query->
plan == NULL)
2944 elog(
ERROR,
"could not open cursor: %s",
2951 if (curname == NULL)
2976 if (curname == NULL)
2998 Oid loop_var_elem_type;
3004 Oid iterator_result_type;
3005 int32 iterator_result_typmod;
3013 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3014 errmsg(
"FOREACH expression must not be null")));
3028 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3029 errmsg(
"FOREACH expression must yield an array, not type %s",
3045 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3046 errmsg(
"slice dimension (%d) is out of the valid range 0..%d",
3072 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3073 errmsg(
"FOREACH ... SLICE loop variable must be of an array type")));
3076 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3077 errmsg(
"FOREACH loop variable must not be of an array type")));
3083 if (
stmt->slice > 0)
3086 iterator_result_type = arrtype;
3087 iterator_result_typmod = arrtypmod;
3093 iterator_result_typmod = arrtypmod;
3106 iterator_result_type, iterator_result_typmod);
3109 if (
stmt->slice > 0)
3153 if (
stmt->cond != NULL)
3160 if (isnull ||
value ==
false)
3208 if (
stmt->retvarno >= 0)
3212 switch (retvar->
dtype)
3238 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3239 errmsg(
"cannot return non-composite value from function returning composite type")));
3279 if (
stmt->expr != NULL)
3295 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3296 errmsg(
"cannot return non-composite value from function returning composite type")));
3334 (
errcode(ERRCODE_SYNTAX_ERROR),
3335 errmsg(
"cannot use RETURN NEXT in a non-SETOF function")));
3342 natts = tupdesc->
natts;
3354 if (
stmt->retvarno >= 0)
3358 switch (retvar->
dtype)
3370 bool isNull = var->
isnull;
3375 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3376 errmsg(
"wrong result type supplied in RETURN NEXT")));
3404 if (rec->
erh == NULL)
3414 gettext_noop(
"wrong record type supplied in RETURN NEXT"));
3434 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3435 errmsg(
"wrong record type supplied in RETURN NEXT")));
3446 else if (
stmt->expr)
3470 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3471 errmsg(
"cannot return non-composite value from function returning composite type")));
3478 gettext_noop(
"returned record type does not match expected record type"));
3491 nulldatums = (
Datum *)
3493 nullflags = (
bool *)
3495 memset(nullflags,
true, natts *
sizeof(
bool));
3497 nulldatums, nullflags);
3507 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3508 errmsg(
"wrong result type supplied in RETURN NEXT")));
3526 (
errcode(ERRCODE_SYNTAX_ERROR),
3527 errmsg(
"RETURN NEXT must have a parameter")));
3554 (
errcode(ERRCODE_SYNTAX_ERROR),
3555 errmsg(
"cannot use RETURN QUERY in a non-SETOF function")));
3573 gettext_noop(
"structure of query does not match function result type"));
3576 if (
stmt->query != NULL)
3586 if (expr->
plan == NULL)
3600 options.must_return_tuples =
true;
3605 elog(
ERROR,
"SPI_execute_plan_extended failed executing query \"%s\": %s",
3624 &isnull, &restype, &restypmod);
3627 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3628 errmsg(
"query string argument of EXECUTE is null")));
3643 options.must_return_tuples =
true;
3648 elog(
ERROR,
"SPI_execute_extended failed executing query \"%s\": %s",
3678 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3679 errmsg(
"set-valued function called in context that cannot accept a set")));
3684 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3685 errmsg(
"materialize mode required, but it is not allowed in this context")));
3708#define SET_RAISE_OPTION_TEXT(opt, name) \
3712 (errcode(ERRCODE_SYNTAX_ERROR), \
3713 errmsg("RAISE option already specified: %s", \
3715 opt = MemoryContextStrdup(stmt_mcontext, extval); \
3726 char *condname = NULL;
3727 char *err_message = NULL;
3728 char *err_detail = NULL;
3729 char *err_hint = NULL;
3730 char *err_column = NULL;
3731 char *err_constraint = NULL;
3732 char *err_datatype = NULL;
3733 char *err_table = NULL;
3734 char *err_schema = NULL;
3739 if (
stmt->condname == NULL &&
stmt->message == NULL &&
3746 (
errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER),
3747 errmsg(
"RAISE without parameters cannot be used outside an exception handler")));
3773 for (cp =
stmt->message; *cp; cp++)
3795 if (current_param == NULL)
3796 elog(
ERROR,
"unexpected RAISE parameter list length");
3811 current_param =
lnext(
stmt->params, current_param);
3819 if (current_param != NULL)
3820 elog(
ERROR,
"unexpected RAISE parameter list length");
3822 err_message = ds.
data;
3825 foreach(lc,
stmt->options)
3840 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3841 errmsg(
"RAISE statement option cannot be null")));
3850 (
errcode(ERRCODE_SYNTAX_ERROR),
3851 errmsg(
"RAISE option already specified: %s",
3888 if (err_code == 0 &&
stmt->elog_level >=
ERROR)
3889 err_code = ERRCODE_RAISE_EXCEPTION;
3892 if (err_message == NULL)
3896 err_message = condname;
3908 (err_code ?
errcode(err_code) : 0,
3911 (err_hint != NULL) ?
errhint(
"%s", err_hint) : 0,
3912 (err_column != NULL) ?
3914 (err_constraint != NULL) ?
3916 (err_datatype != NULL) ?
3918 (err_table != NULL) ?
3920 (err_schema != NULL) ?
3946 if (isnull || !
value)
3948 char *message = NULL;
3950 if (
stmt->message != NULL)
3957 &isnull, &
typeid, &typmod);
3964 (
errcode(ERRCODE_ASSERT_FAILURE),
3966 errmsg(
"assertion failed")));
3980 EState *simple_eval_estate,
3988 estate->
func = func;
4048 if (simple_eval_estate)
4076 if (simple_eval_resowner)
4121 if ((*plpgsql_plugin_ptr)->func_setup)
4122 ((*plpgsql_plugin_ptr)->func_setup) (estate, func);
4188 options.parserSetupArg = expr;
4190 options.cursorOptions = cursorOptions;
4193 elog(
ERROR,
"SPI_prepare_extended failed for \"%s\": %s",
4219 int too_many_rows_level = 0;
4222 too_many_rows_level =
ERROR;
4224 too_many_rows_level =
WARNING;
4230 if (expr->
plan == NULL)
4233 if (!
stmt->mod_stmt_set)
4237 stmt->mod_stmt =
false;
4249 if (plansource->
commandTag == CMDTAG_INSERT ||
4254 stmt->mod_stmt =
true;
4258 stmt->mod_stmt_set =
true;
4280 if (
stmt->strict ||
stmt->mod_stmt || too_many_rows_level)
4337 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4338 errmsg(
"cannot COPY to/from client in PL/pgSQL")));
4343 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4344 errmsg(
"unsupported transaction command in PL/pgSQL")));
4348 elog(
ERROR,
"SPI_execute_plan_with_paramlist failed executing query \"%s\": %s",
4366 (
errcode(ERRCODE_SYNTAX_ERROR),
4367 errmsg(
"INTO used with a command that cannot return data")));
4389 (
errcode(ERRCODE_NO_DATA_FOUND),
4390 errmsg(
"query returned no rows"),
4398 if (n > 1 && (
stmt->strict ||
stmt->mod_stmt || too_many_rows_level))
4408 errlevel = (
stmt->strict ||
stmt->mod_stmt) ?
ERROR : too_many_rows_level;
4411 (
errcode(ERRCODE_TOO_MANY_ROWS),
4412 errmsg(
"query returned more than one row"),
4414 errhint(
"Make sure the query returns a single row, or use LIMIT 1.")));
4429 (
errcode(ERRCODE_SYNTAX_ERROR),
4430 errmsg(
"query has no destination for result data"),
4431 (rc ==
SPI_OK_SELECT) ?
errhint(
"If you want to discard the results of a SELECT, use PERFORM instead.") : 0));
4464 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4465 errmsg(
"query string argument of EXECUTE is null")));
4519 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4520 errmsg(
"EXECUTE of SELECT ... INTO is not implemented"),
4521 errhint(
"You might want to use EXECUTE ... INTO or EXECUTE CREATE TABLE ... AS instead.")));
4527 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4528 errmsg(
"cannot COPY to/from client in PL/pgSQL")));
4533 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4534 errmsg(
"EXECUTE of transaction commands is not implemented")));
4538 elog(
ERROR,
"SPI_execute_extended failed executing query \"%s\": %s",
4556 (
errcode(ERRCODE_SYNTAX_ERROR),
4557 errmsg(
"INTO used with a command that cannot return data")));
4579 (
errcode(ERRCODE_NO_DATA_FOUND),
4580 errmsg(
"query returned no rows"),
4588 if (n > 1 &&
stmt->strict)
4598 (
errcode(ERRCODE_TOO_MANY_ROWS),
4599 errmsg(
"query returned more than one row"),
4665 char *curname = NULL;
4688 (
errcode(ERRCODE_DUPLICATE_CURSOR),
4689 errmsg(
"cursor \"%s\" already in use", curname)));
4696 if (
stmt->query != NULL)
4705 query =
stmt->query;
4706 if (query->
plan == NULL)
4709 else if (
stmt->dynquery != NULL)
4719 stmt->cursor_options);
4729 if (curname == NULL)
4746 if (
stmt->argquery != NULL)
4758 (
errcode(ERRCODE_SYNTAX_ERROR),
4759 errmsg(
"arguments given for cursor without arguments")));
4761 memset(&set_args, 0,
sizeof(set_args));
4765 set_args.
into =
true;
4771 elog(
ERROR,
"open cursor failed during argument processing");
4777 (
errcode(ERRCODE_SYNTAX_ERROR),
4778 errmsg(
"arguments required for cursor")));
4782 if (query->
plan == NULL)
4798 elog(
ERROR,
"could not open cursor: %s",
4805 if (curname == NULL)
4829 long how_many =
stmt->how_many;
4843 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4844 errmsg(
"cursor variable \"%s\" is null", curvar->
refname)));
4854 (
errcode(ERRCODE_UNDEFINED_CURSOR),
4855 errmsg(
"cursor \"%s\" does not exist", curname)));
4867 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4868 errmsg(
"relative or absolute cursor position is null")));
4931 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4932 errmsg(
"cursor variable \"%s\" is null", curvar->
refname)));
4942 (
errcode(ERRCODE_UNDEFINED_CURSOR),
4943 errmsg(
"cursor \"%s\" does not exist", curname)));
5018 if (expr->
plan == NULL)
5084 switch (target->
dtype)
5105 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5106 errmsg(
"null value cannot be assigned to variable \"%s\" declared NOT NULL",
5155 if (var->
value != newvalue || var->
isnull || isNull)
5181 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5182 errmsg(
"cannot assign non-composite value to a row variable")));
5200 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5201 errmsg(
"null value cannot be assigned to variable \"%s\" declared NOT NULL",
5213 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5214 errmsg(
"cannot assign non-composite value to a record variable")));
5255 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5256 errmsg(
"record \"%s\" has no field \"%s\"",
5264 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5265 errmsg(
"cannot assign to system column \"%s\"",
5315 switch (datum->
dtype)
5341 elog(
ERROR,
"row variable has no tupdesc");
5347 elog(
ERROR,
"row not compatible with its own tupdesc");
5360 if (rec->
erh == NULL)
5428 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5429 errmsg(
"record \"%s\" has no field \"%s\"",
5462 switch (datum->
dtype)
5502 if (rec->
erh == NULL)
5515 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5516 errmsg(
"record \"%s\" has no field \"%s\"",
5546 switch (datum->
dtype)
5593 if (rec->
erh == NULL)
5606 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5607 errmsg(
"record \"%s\" has no field \"%s\"",
5645 exprdatum =
exec_eval_expr(estate, expr, isNull, &exprtypeid, &exprtypmod);
5647 exprtypeid, exprtypmod,
5668 exprdatum =
exec_eval_expr(estate, expr, isNull, &exprtypeid, &exprtypmod);
5670 exprtypeid, exprtypmod,
5696 if (expr->
plan == NULL)
5704 &result, isNull, rettype, rettypmod))
5713 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
5714 errmsg(
"query did not return data"),
5722 (
errcode(ERRCODE_SYNTAX_ERROR),
5724 "query returned %d columns",
5733 *rettype = attr->atttypid;
5734 *rettypmod = attr->atttypmod;
5750 (
errcode(ERRCODE_CARDINALITY_VIOLATION),
5751 errmsg(
"query returned more than one row"),
5784 if (expr->
plan == NULL)
5788 if (portalP == NULL)
5801 if (portalP != NULL)
5806 if (*portalP == NULL)
5807 elog(
ERROR,
"could not open implicit cursor for query \"%s\": %s",
5826 (
errcode(ERRCODE_SYNTAX_ERROR),
5827 errmsg(
"query is SELECT INTO, but it should be plain SELECT"),
5831 (
errcode(ERRCODE_SYNTAX_ERROR),
5832 errmsg(
"query is not a SELECT"),
5852 Portal portal,
bool prefetch_ok)
5859 bool tupdescs_match =
true;
5880 prefetch_ok =
false;
5910 for (
i = 0;
i < n;
i++)
6043 void *save_setup_arg;
6317 int paramid,
bool speculative,
6329 Assert(dno >= 0 && dno < params->numParams);
6337 datum = estate->
datums[dno];
6353 else if (speculative)
6355 switch (datum->
dtype)
6380 if (rec->
erh == NULL)
6417 &prm->
ptype, &prmtypmod,
6445 Datum *resv,
bool *resnull)
6459 Assert(dno >= 0 && dno < estate->ndatums);
6462 datum = estate->
datums[dno];
6529 Assert(dno >= 0 && dno < estate->ndatums);
6561 Assert(dno >= 0 && dno < estate->ndatums);
6600 Assert(dno >= 0 && dno < estate->ndatums);
6631 (
errcode(ERRCODE_UNDEFINED_COLUMN),
6632 errmsg(
"record \"%s\" has no field \"%s\"",
6645 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6646 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6672 Assert(dno >= 0 && dno < estate->ndatums);
6675 datum = estate->
datums[dno];
6679 &datumtype, &datumtypmod,
6685 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6686 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6712 Assert(dno >= 0 && dno < estate->ndatums);
6715 datum = estate->
datums[dno];
6719 &datumtype, &datumtypmod,
6725 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6726 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6768 if (tupdesc == NULL)
6839 int td_natts = tupdesc->
natts;
6842 Datum values_local[64];
6843 bool nulls_local[64];
6850 if (td_natts <=
lengthof(values_local))
6853 nulls = nulls_local;
6860 td_natts * (
sizeof(
Datum) +
sizeof(
bool)));
6862 nulls = (
bool *) (
chunk + td_natts *
sizeof(
Datum));
6922 if (typentry->
typtype == TYPTYPE_DOMAIN)
6925 if (typentry->
tupDesc == NULL)
6932 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6933 errmsg(
"type %s is not composite",
7033 int td_natts = tupdesc ? tupdesc->
natts : 0;
7036 int strict_multiassignment_level = 0;
7042 if (tupdesc != NULL)
7045 strict_multiassignment_level =
ERROR;
7047 strict_multiassignment_level =
WARNING;
7055 Datum newvalues_local[64];
7056 bool newnulls_local[64];
7071 if (var_tupdesc != tupdesc)
7073 int vtd_natts = var_tupdesc->
natts;
7082 if (vtd_natts <=
lengthof(newvalues_local))
7084 newvalues = newvalues_local;
7085 newnulls = newnulls_local;
7092 vtd_natts * (
sizeof(
Datum) +
sizeof(
bool)));
7094 newnulls = (
bool *) (
chunk + vtd_natts *
sizeof(
Datum));
7099 for (fnum = 0; fnum < vtd_natts; fnum++)
7107 if (attr->attisdropped)
7113 while (anum < td_natts &&
7117 if (anum < td_natts)
7120 isnull = nulls[anum];
7130 valtype = UNKNOWNOID;
7134 if (strict_multiassignment_level)
7135 ereport(strict_multiassignment_level,
7136 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7137 errmsg(
"number of source and target fields in assignment does not match"),
7140 "strict_multi_assignment",
7141 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7143 errhint(
"Make sure the query returns the exact list of columns.")));
7154 newnulls[fnum] = isnull;
7161 if (strict_multiassignment_level && anum < td_natts)
7164 while (anum < td_natts &&
7168 if (anum < td_natts)
7169 ereport(strict_multiassignment_level,
7170 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7171 errmsg(
"number of source and target fields in assignment does not match"),
7174 "strict_multi_assignment",
7175 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7177 errhint(
"Make sure the query returns the exact list of columns.")));
7212 for (fnum = 0; fnum < row->
nfields; fnum++)
7222 while (anum < td_natts &&
7226 if (anum < td_natts)
7229 isnull = nulls[anum];
7239 valtype = UNKNOWNOID;
7242 if (strict_multiassignment_level)
7243 ereport(strict_multiassignment_level,
7244 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7245 errmsg(
"number of source and target fields in assignment does not match"),
7248 "strict_multi_assignment",
7249 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7251 errhint(
"Make sure the query returns the exact list of columns.")));
7255 value, isnull, valtype, valtypmod);
7262 if (strict_multiassignment_level && anum < td_natts)
7264 while (anum < td_natts &&
7268 if (anum < td_natts)
7269 ereport(strict_multiassignment_level,
7270 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7271 errmsg(
"number of source and target fields in assignment does not match"),
7274 "strict_multi_assignment",
7275 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7277 errhint(
"Make sure the query returns the exact list of columns.")));
7298 if (dst_tupdesc->
natts != src_tupdesc->
natts)
7301 for (
i = 0;
i < dst_tupdesc->
natts;
i++)
7306 if (dattr->attisdropped != sattr->attisdropped)
7308 if (!dattr->attisdropped)
7311 if (dattr->atttypid != sattr->atttypid ||
7312 (dattr->atttypmod >= 0 &&
7313 dattr->atttypmod != sattr->atttypmod))
7319 if (dattr->attlen != sattr->attlen ||
7320 dattr->attalign != sattr->attalign)
7341 int natts = tupdesc->
natts;
7353 for (
i = 0;
i < natts;
i++)
7365 &fieldtypeid, &fieldtypmod,
7366 &dvalues[
i], &nulls[
i]);
7447 if (erh == rec->
erh)
7601 (tupType != RECORDOID ||
7663 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
7665 errdetail(
"The tuple structure of a not-yet-assigned record is indeterminate.")));
7728 if (valtype != reqtype ||
7729 (valtypmod != reqtypmod && reqtypmod != -1))
7733 reqtype, reqtypmod);
7753 reqtype, reqtypmod);
7860 placeholder->
typeId = srctype;
7861 placeholder->typeMod = srctypmod;
7879 if (srctype == UNKNOWNOID || srctype == RECORDOID)
7883 (
Node *) placeholder, srctype,
7896 if (cast_expr == NULL)
7900 iocoerce->
arg = (
Expr *) placeholder;
7905 cast_expr = (
Node *) iocoerce;
7906 if (dsttypmod != -1)
7919 cast_expr = cast_cexpr->
expr;
8087 if (query->hasAggs ||
8088 query->hasWindowFuncs ||
8089 query->hasTargetSRFs ||
8090 query->hasSubLinks ||
8155 plan->righttree == NULL &&
8156 plan->initPlan == NULL &&
8157 plan->qual == NULL &&
8164 plan->righttree == NULL &&
8165 plan->initPlan == NULL &&
8166 plan->qual == NULL);
8177 elog(
ERROR,
"unexpected plan node type: %d",
8262 fargs = fexpr->
args;
8268 funcid = opexpr->opfuncid;
8269 fargs = opexpr->
args;
8277 F_ARRAY_SUBSCRIPT_HANDLER)
8286 param->
paramid == target_dno + 1)
8304 if (!(funcid == F_ARRAY_APPEND ||
8305 funcid == F_ARRAY_PREPEND))
8323 param->
paramid == target_dno + 1)
8343 Assert(dno >= 0 && dno < estate->ndatums);
8344 datum = estate->
datums[dno];
8345 switch (datum->
dtype)
8352 (
errcode(ERRCODE_ERROR_IN_ASSIGNMENT),
8353 errmsg(
"variable \"%s\" is declared CONSTANT",
8429 "PL/pgSQL simple expressions");
8552 Datum newvalue,
bool isnull,
bool freeable)
8586 newvalue =
datumCopy(detoasted,
false, -1);
8602 var->
value = newvalue;
8689 if (prm->
ptype == UNKNOWNOID)
8698 prm->
ptype = TEXTOID;
8735 const char *portalname,
8751 query =
exec_eval_expr(estate, dynquery, &isnull, &restype, &restypmod);
8754 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
8755 errmsg(
"query string argument of EXECUTE is null")));
8772 options.cursorOptions = cursorOptions;
8778 elog(
ERROR,
"could not open implicit cursor for query \"%s\": %s",
8820 ¶mtypeid, ¶mtypmod,
8821 ¶mdatum, ¶misnull);
8824 paramno > 0 ?
", " :
"",
8841 return paramstr.
data;
8863 for (paramno = 0; paramno < paramLI->
numParams; paramno++)
8873 paramno > 0 ?
", " :
"",
8888 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)
#define Assert(condition)
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 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)
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)
#define HeapTupleHeaderSetTypMod(tup, typmod)
#define HeapTupleHeaderGetTypMod(tup)
#define HeapTupleHeaderGetTypeId(tup)
#define HeapTupleHeaderGetDatumLength(tup)
#define HeapTupleHeaderSetTypeId(tup, typeid)
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)
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 IsA(nodeptr, _type_)
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)
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)
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 void exec_check_rw_parameter(PLpgSQL_expr *expr)
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)
void plpgsql_subxact_cb(SubXactEvent event, SubTransactionId mySubid, SubTransactionId parentSubid, void *arg)
static void plpgsql_param_eval_var(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 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)
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)
MemoryContextSwitchTo(old_ctx)
#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
ExecEvalSubroutine paramfunc
union ExprEvalStep::@55 d
struct ExprEvalStep::@55::@68 cparam
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
struct PLpgSQL_function * func
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