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;
1328 ws_next = workspace;
1332 outdatums = estate->
datums;
1333 for (
i = 0;
i < ndatums;
i++)
1339 switch (indatum->
dtype)
1371 outdatums[
i] = outdatum;
1404 elog(
ERROR,
"trigger promise is not in a trigger function");
1413 elog(
ERROR,
"trigger promise is not in a trigger function");
1421 elog(
ERROR,
"unrecognized trigger execution time: not BEFORE, AFTER, or INSTEAD OF");
1426 elog(
ERROR,
"trigger promise is not in a trigger function");
1432 elog(
ERROR,
"unrecognized trigger event type: not ROW or STATEMENT");
1437 elog(
ERROR,
"trigger promise is not in a trigger function");
1447 elog(
ERROR,
"unrecognized trigger action: not INSERT, DELETE, UPDATE, or TRUNCATE");
1452 elog(
ERROR,
"trigger promise is not in a trigger function");
1460 elog(
ERROR,
"trigger promise is not in a trigger function");
1469 elog(
ERROR,
"trigger promise is not in a trigger function");
1478 elog(
ERROR,
"trigger promise is not in a trigger function");
1486 elog(
ERROR,
"trigger promise is not in a trigger function");
1500 for (
i = 0;
i < nelems;
i++)
1509 -1,
false, TYPALIGN_INT)),
1520 elog(
ERROR,
"event trigger promise is not in an event trigger function");
1526 elog(
ERROR,
"event trigger promise is not in an event trigger function");
1549 "PLpgSQL per-statement data",
1596 for (; cond != NULL; cond = cond->
next)
1607 if (edata->
sqlerrcode != ERRCODE_QUERY_CANCELED &&
1641 ((*plpgsql_plugin_ptr)->stmt_beg) (estate, (
PLpgSQL_stmt *) block);
1649 ((*plpgsql_plugin_ptr)->stmt_end) (estate, (
PLpgSQL_stmt *) block);
1664 volatile int rc = -1;
1689 switch (datum->
dtype)
1823 resTypByVal, resTypLen);
1974 if (block->
label == NULL)
2020 ((*plpgsql_plugin_ptr)->stmt_beg) (estate,
stmt);
2024 switch (
stmt->cmd_type)
2143 ((*plpgsql_plugin_ptr)->stmt_end) (estate,
stmt);
2208 if (expr->
plan == NULL)
2221 if (
stmt->is_call &&
stmt->target == NULL)
2238 options.allow_nonatomic =
true;
2244 elog(
ERROR,
"SPI_execute_plan_extended failed executing query \"%s\": %s",
2249 if (before_lxid != after_lxid)
2269 elog(
ERROR,
"DO statement returned a row");
2274 elog(
ERROR,
"procedure call returned more than one row");
2314 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2318 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2320 funcexpr =
stmt->funcexpr;
2325 elog(
ERROR,
"cache lookup failed for function %u",
2344 row->
refname =
"(unnamed row)";
2356 for (
i = 0;
i < numargs;
i++)
2359 (argmodes[
i] == PROARGMODE_INOUT ||
2360 argmodes[
i] == PROARGMODE_OUT))
2373 row->
varnos[nfields++] = dno;
2378 if (argnames && argnames[
i] && argnames[
i][0])
2380 (
errcode(ERRCODE_SYNTAX_ERROR),
2381 errmsg(
"procedure parameter \"%s\" is an output parameter but corresponding argument is not writable",
2385 (
errcode(ERRCODE_SYNTAX_ERROR),
2386 errmsg(
"procedure parameter %d is an output parameter but corresponding argument is not writable",
2421 (
errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER),
2422 errmsg(
"GET STACKED DIAGNOSTICS cannot be used outside an exception handler")));
2424 foreach(lc,
stmt->diag_items)
2429 switch (diag_item->
kind)
2434 false, INT8OID, -1);
2495 char *contextstackstr;
2508 elog(
ERROR,
"unrecognized diagnostic item kind: %d",
2533 if (!isnull &&
value)
2536 foreach(lc,
stmt->elsif_list)
2542 if (!isnull &&
value)
2561 if (
stmt->t_expr != NULL)
2569 &isnull, &t_typoid, &t_typmod);
2600 foreach(l,
stmt->case_when_list)
2607 if (!isnull &&
value)
2625 if (!
stmt->have_else)
2627 (
errcode(ERRCODE_CASE_NOT_FOUND),
2628 errmsg(
"case not found"),
2629 errhint(
"CASE statement is missing ELSE part.")));
2676 if (isnull || !
value)
2714 &isnull, &valtype, &valtypmod);
2721 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2722 errmsg(
"lower bound of FOR loop cannot be null")));
2730 &isnull, &valtype, &valtypmod);
2737 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2738 errmsg(
"upper bound of FOR loop cannot be null")));
2748 &isnull, &valtype, &valtypmod);
2755 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2756 errmsg(
"BY value of FOR loop cannot be null")));
2759 if (step_value <= 0)
2761 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2762 errmsg(
"BY value of FOR loop must be greater than zero")));
2777 if (loop_value < end_value)
2782 if (loop_value > end_value)
2808 loop_value -= step_value;
2814 loop_value += step_value;
2871 char *curname = NULL;
2895 (
errcode(ERRCODE_DUPLICATE_CURSOR),
2896 errmsg(
"cursor \"%s\" already in use", curname)));
2906 if (
stmt->argquery != NULL)
2918 (
errcode(ERRCODE_SYNTAX_ERROR),
2919 errmsg(
"arguments given for cursor without arguments")));
2921 memset(&set_args, 0,
sizeof(set_args));
2925 set_args.
into =
true;
2931 elog(
ERROR,
"open cursor failed during argument processing");
2937 (
errcode(ERRCODE_SYNTAX_ERROR),
2938 errmsg(
"arguments required for cursor")));
2944 if (query->
plan == NULL)
2959 elog(
ERROR,
"could not open cursor: %s",
2966 if (curname == NULL)
2991 if (curname == NULL)
3013 Oid loop_var_elem_type;
3019 Oid iterator_result_type;
3020 int32 iterator_result_typmod;
3028 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3029 errmsg(
"FOREACH expression must not be null")));
3043 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3044 errmsg(
"FOREACH expression must yield an array, not type %s",
3060 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3061 errmsg(
"slice dimension (%d) is out of the valid range 0..%d",
3087 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3088 errmsg(
"FOREACH ... SLICE loop variable must be of an array type")));
3091 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3092 errmsg(
"FOREACH loop variable must not be of an array type")));
3098 if (
stmt->slice > 0)
3101 iterator_result_type = arrtype;
3102 iterator_result_typmod = arrtypmod;
3108 iterator_result_typmod = arrtypmod;
3121 iterator_result_type, iterator_result_typmod);
3124 if (
stmt->slice > 0)
3168 if (
stmt->cond != NULL)
3175 if (isnull ||
value ==
false)
3223 if (
stmt->retvarno >= 0)
3227 switch (retvar->
dtype)
3253 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3254 errmsg(
"cannot return non-composite value from function returning composite type")));
3294 if (
stmt->expr != NULL)
3310 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3311 errmsg(
"cannot return non-composite value from function returning composite type")));
3349 (
errcode(ERRCODE_SYNTAX_ERROR),
3350 errmsg(
"cannot use RETURN NEXT in a non-SETOF function")));
3357 natts = tupdesc->
natts;
3369 if (
stmt->retvarno >= 0)
3373 switch (retvar->
dtype)
3385 bool isNull = var->
isnull;
3390 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3391 errmsg(
"wrong result type supplied in RETURN NEXT")));
3419 if (rec->
erh == NULL)
3429 gettext_noop(
"wrong record type supplied in RETURN NEXT"));
3449 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3450 errmsg(
"wrong record type supplied in RETURN NEXT")));
3461 else if (
stmt->expr)
3485 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3486 errmsg(
"cannot return non-composite value from function returning composite type")));
3493 gettext_noop(
"returned record type does not match expected record type"));
3506 nulldatums = (
Datum *)
3508 nullflags = (
bool *)
3510 memset(nullflags,
true, natts *
sizeof(
bool));
3512 nulldatums, nullflags);
3522 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3523 errmsg(
"wrong result type supplied in RETURN NEXT")));
3541 (
errcode(ERRCODE_SYNTAX_ERROR),
3542 errmsg(
"RETURN NEXT must have a parameter")));
3569 (
errcode(ERRCODE_SYNTAX_ERROR),
3570 errmsg(
"cannot use RETURN QUERY in a non-SETOF function")));
3588 gettext_noop(
"structure of query does not match function result type"));
3591 if (
stmt->query != NULL)
3601 if (expr->
plan == NULL)
3615 options.must_return_tuples =
true;
3620 elog(
ERROR,
"SPI_execute_plan_extended failed executing query \"%s\": %s",
3639 &isnull, &restype, &restypmod);
3642 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3643 errmsg(
"query string argument of EXECUTE is null")));
3658 options.must_return_tuples =
true;
3663 elog(
ERROR,
"SPI_execute_extended failed executing query \"%s\": %s",
3693 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3694 errmsg(
"set-valued function called in context that cannot accept a set")));
3699 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3700 errmsg(
"materialize mode required, but it is not allowed in this context")));
3723#define SET_RAISE_OPTION_TEXT(opt, name) \
3727 (errcode(ERRCODE_SYNTAX_ERROR), \
3728 errmsg("RAISE option already specified: %s", \
3730 opt = MemoryContextStrdup(stmt_mcontext, extval); \
3741 char *condname = NULL;
3742 char *err_message = NULL;
3743 char *err_detail = NULL;
3744 char *err_hint = NULL;
3745 char *err_column = NULL;
3746 char *err_constraint = NULL;
3747 char *err_datatype = NULL;
3748 char *err_table = NULL;
3749 char *err_schema = NULL;
3754 if (
stmt->condname == NULL &&
stmt->message == NULL &&
3761 (
errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER),
3762 errmsg(
"RAISE without parameters cannot be used outside an exception handler")));
3788 for (cp =
stmt->message; *cp; cp++)
3810 if (current_param == NULL)
3811 elog(
ERROR,
"unexpected RAISE parameter list length");
3826 current_param =
lnext(
stmt->params, current_param);
3834 if (current_param != NULL)
3835 elog(
ERROR,
"unexpected RAISE parameter list length");
3837 err_message = ds.
data;
3840 foreach(lc,
stmt->options)
3855 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3856 errmsg(
"RAISE statement option cannot be null")));
3865 (
errcode(ERRCODE_SYNTAX_ERROR),
3866 errmsg(
"RAISE option already specified: %s",
3903 if (err_code == 0 &&
stmt->elog_level >=
ERROR)
3904 err_code = ERRCODE_RAISE_EXCEPTION;
3907 if (err_message == NULL)
3911 err_message = condname;
3923 (err_code ?
errcode(err_code) : 0,
3926 (err_hint != NULL) ?
errhint(
"%s", err_hint) : 0,
3927 (err_column != NULL) ?
3929 (err_constraint != NULL) ?
3931 (err_datatype != NULL) ?
3933 (err_table != NULL) ?
3935 (err_schema != NULL) ?
3961 if (isnull || !
value)
3963 char *message = NULL;
3965 if (
stmt->message != NULL)
3972 &isnull, &
typeid, &typmod);
3979 (
errcode(ERRCODE_ASSERT_FAILURE),
3981 errmsg(
"assertion failed")));
3995 EState *simple_eval_estate,
4003 estate->
func = func;
4063 if (simple_eval_estate)
4091 if (simple_eval_resowner)
4136 if ((*plpgsql_plugin_ptr)->func_setup)
4137 ((*plpgsql_plugin_ptr)->func_setup) (estate, func);
4197 options.parserSetupArg = expr;
4199 options.cursorOptions = cursorOptions;
4202 elog(
ERROR,
"SPI_prepare_extended failed for \"%s\": %s",
4228 int too_many_rows_level = 0;
4231 too_many_rows_level =
ERROR;
4233 too_many_rows_level =
WARNING;
4239 if (expr->
plan == NULL)
4242 if (!
stmt->mod_stmt_set)
4246 stmt->mod_stmt =
false;
4258 if (plansource->
commandTag == CMDTAG_INSERT ||
4263 stmt->mod_stmt =
true;
4267 stmt->mod_stmt_set =
true;
4289 if (
stmt->strict ||
stmt->mod_stmt || too_many_rows_level)
4346 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4347 errmsg(
"cannot COPY to/from client in PL/pgSQL")));
4352 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4353 errmsg(
"unsupported transaction command in PL/pgSQL")));
4357 elog(
ERROR,
"SPI_execute_plan_with_paramlist failed executing query \"%s\": %s",
4375 (
errcode(ERRCODE_SYNTAX_ERROR),
4376 errmsg(
"INTO used with a command that cannot return data")));
4398 (
errcode(ERRCODE_NO_DATA_FOUND),
4399 errmsg(
"query returned no rows"),
4407 if (n > 1 && (
stmt->strict ||
stmt->mod_stmt || too_many_rows_level))
4417 errlevel = (
stmt->strict ||
stmt->mod_stmt) ?
ERROR : too_many_rows_level;
4420 (
errcode(ERRCODE_TOO_MANY_ROWS),
4421 errmsg(
"query returned more than one row"),
4423 errhint(
"Make sure the query returns a single row, or use LIMIT 1.")));
4438 (
errcode(ERRCODE_SYNTAX_ERROR),
4439 errmsg(
"query has no destination for result data"),
4440 (rc ==
SPI_OK_SELECT) ?
errhint(
"If you want to discard the results of a SELECT, use PERFORM instead.") : 0));
4473 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4474 errmsg(
"query string argument of EXECUTE is null")));
4528 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4529 errmsg(
"EXECUTE of SELECT ... INTO is not implemented"),
4530 errhint(
"You might want to use EXECUTE ... INTO or EXECUTE CREATE TABLE ... AS instead.")));
4536 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4537 errmsg(
"cannot COPY to/from client in PL/pgSQL")));
4542 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4543 errmsg(
"EXECUTE of transaction commands is not implemented")));
4547 elog(
ERROR,
"SPI_execute_extended failed executing query \"%s\": %s",
4565 (
errcode(ERRCODE_SYNTAX_ERROR),
4566 errmsg(
"INTO used with a command that cannot return data")));
4588 (
errcode(ERRCODE_NO_DATA_FOUND),
4589 errmsg(
"query returned no rows"),
4597 if (n > 1 &&
stmt->strict)
4607 (
errcode(ERRCODE_TOO_MANY_ROWS),
4608 errmsg(
"query returned more than one row"),
4674 char *curname = NULL;
4697 (
errcode(ERRCODE_DUPLICATE_CURSOR),
4698 errmsg(
"cursor \"%s\" already in use", curname)));
4705 if (
stmt->query != NULL)
4714 query =
stmt->query;
4715 if (query->
plan == NULL)
4718 else if (
stmt->dynquery != NULL)
4728 stmt->cursor_options);
4738 if (curname == NULL)
4755 if (
stmt->argquery != NULL)
4767 (
errcode(ERRCODE_SYNTAX_ERROR),
4768 errmsg(
"arguments given for cursor without arguments")));
4770 memset(&set_args, 0,
sizeof(set_args));
4774 set_args.
into =
true;
4780 elog(
ERROR,
"open cursor failed during argument processing");
4786 (
errcode(ERRCODE_SYNTAX_ERROR),
4787 errmsg(
"arguments required for cursor")));
4791 if (query->
plan == NULL)
4807 elog(
ERROR,
"could not open cursor: %s",
4814 if (curname == NULL)
4838 long how_many =
stmt->how_many;
4852 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4853 errmsg(
"cursor variable \"%s\" is null", curvar->
refname)));
4863 (
errcode(ERRCODE_UNDEFINED_CURSOR),
4864 errmsg(
"cursor \"%s\" does not exist", curname)));
4876 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4877 errmsg(
"relative or absolute cursor position is null")));
4940 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4941 errmsg(
"cursor variable \"%s\" is null", curvar->
refname)));
4951 (
errcode(ERRCODE_UNDEFINED_CURSOR),
4952 errmsg(
"cursor \"%s\" does not exist", curname)));
5027 if (expr->
plan == NULL)
5079 switch (target->
dtype)
5100 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5101 errmsg(
"null value cannot be assigned to variable \"%s\" declared NOT NULL",
5150 if (var->
value != newvalue || var->
isnull || isNull)
5176 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5177 errmsg(
"cannot assign non-composite value to a row variable")));
5195 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5196 errmsg(
"null value cannot be assigned to variable \"%s\" declared NOT NULL",
5208 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5209 errmsg(
"cannot assign non-composite value to a record variable")));
5250 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5251 errmsg(
"record \"%s\" has no field \"%s\"",
5259 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5260 errmsg(
"cannot assign to system column \"%s\"",
5310 switch (datum->
dtype)
5336 elog(
ERROR,
"row variable has no tupdesc");
5342 elog(
ERROR,
"row not compatible with its own tupdesc");
5355 if (rec->
erh == NULL)
5423 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5424 errmsg(
"record \"%s\" has no field \"%s\"",
5457 switch (datum->
dtype)
5497 if (rec->
erh == NULL)
5510 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5511 errmsg(
"record \"%s\" has no field \"%s\"",
5541 switch (datum->
dtype)
5588 if (rec->
erh == NULL)
5601 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5602 errmsg(
"record \"%s\" has no field \"%s\"",
5640 exprdatum =
exec_eval_expr(estate, expr, isNull, &exprtypeid, &exprtypmod);
5642 exprtypeid, exprtypmod,
5663 exprdatum =
exec_eval_expr(estate, expr, isNull, &exprtypeid, &exprtypmod);
5665 exprtypeid, exprtypmod,
5691 if (expr->
plan == NULL)
5699 &result, isNull, rettype, rettypmod))
5708 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
5709 errmsg(
"query did not return data"),
5717 (
errcode(ERRCODE_SYNTAX_ERROR),
5719 "query returned %d columns",
5728 *rettype = attr->atttypid;
5729 *rettypmod = attr->atttypmod;
5745 (
errcode(ERRCODE_CARDINALITY_VIOLATION),
5746 errmsg(
"query returned more than one row"),
5783 if (expr->
plan == NULL)
5787 if (portalP == NULL)
5800 if (portalP != NULL)
5805 if (*portalP == NULL)
5806 elog(
ERROR,
"could not open implicit cursor for query \"%s\": %s",
5825 (
errcode(ERRCODE_SYNTAX_ERROR),
5826 errmsg(
"query is SELECT INTO, but it should be plain SELECT"),
5830 (
errcode(ERRCODE_SYNTAX_ERROR),
5831 errmsg(
"query is not a SELECT"),
5851 Portal portal,
bool prefetch_ok)
5858 bool tupdescs_match =
true;
5879 prefetch_ok =
false;
5909 for (
i = 0;
i < n;
i++)
6042 void *save_setup_arg;
6312 int paramid,
bool speculative,
6324 Assert(dno >= 0 && dno < params->numParams);
6332 datum = estate->
datums[dno];
6348 else if (speculative)
6350 switch (datum->
dtype)
6375 if (rec->
erh == NULL)
6412 &prm->
ptype, &prmtypmod,
6440 Datum *resv,
bool *resnull)
6454 Assert(dno >= 0 && dno < estate->ndatums);
6457 datum = estate->
datums[dno];
6480 bool isvarlena = (((
PLpgSQL_var *) datum)->datatype->typlen == -1);
6493 if (((
PLpgSQL_var *) datum)->datatype->typlen == -1)
6543 Assert(dno >= 0 && dno < estate->ndatums);
6640 Assert(dno >= 0 && dno < estate->ndatums);
6696 Assert(dno >= 0 && dno < estate->ndatums);
6728 Assert(dno >= 0 && dno < estate->ndatums);
6767 Assert(dno >= 0 && dno < estate->ndatums);
6798 (
errcode(ERRCODE_UNDEFINED_COLUMN),
6799 errmsg(
"record \"%s\" has no field \"%s\"",
6812 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6813 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6839 Assert(dno >= 0 && dno < estate->ndatums);
6842 datum = estate->
datums[dno];
6846 &datumtype, &datumtypmod,
6852 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6853 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6879 Assert(dno >= 0 && dno < estate->ndatums);
6882 datum = estate->
datums[dno];
6886 &datumtype, &datumtypmod,
6892 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6893 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6935 if (tupdesc == NULL)
7006 int td_natts = tupdesc->
natts;
7009 Datum values_local[64];
7010 bool nulls_local[64];
7017 if (td_natts <=
lengthof(values_local))
7020 nulls = nulls_local;
7027 td_natts * (
sizeof(
Datum) +
sizeof(
bool)));
7029 nulls = (
bool *) (chunk + td_natts *
sizeof(
Datum));
7089 if (typentry->
typtype == TYPTYPE_DOMAIN)
7092 if (typentry->
tupDesc == NULL)
7099 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
7100 errmsg(
"type %s is not composite",
7200 int td_natts = tupdesc ? tupdesc->
natts : 0;
7203 int strict_multiassignment_level = 0;
7209 if (tupdesc != NULL)
7212 strict_multiassignment_level =
ERROR;
7214 strict_multiassignment_level =
WARNING;
7222 Datum newvalues_local[64];
7223 bool newnulls_local[64];
7238 if (var_tupdesc != tupdesc)
7240 int vtd_natts = var_tupdesc->
natts;
7249 if (vtd_natts <=
lengthof(newvalues_local))
7251 newvalues = newvalues_local;
7252 newnulls = newnulls_local;
7259 vtd_natts * (
sizeof(
Datum) +
sizeof(
bool)));
7260 newvalues = (
Datum *) chunk;
7261 newnulls = (
bool *) (chunk + vtd_natts *
sizeof(
Datum));
7266 for (fnum = 0; fnum < vtd_natts; fnum++)
7274 if (attr->attisdropped)
7280 while (anum < td_natts &&
7284 if (anum < td_natts)
7287 isnull = nulls[anum];
7297 valtype = UNKNOWNOID;
7301 if (strict_multiassignment_level)
7302 ereport(strict_multiassignment_level,
7303 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7304 errmsg(
"number of source and target fields in assignment does not match"),
7307 "strict_multi_assignment",
7308 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7310 errhint(
"Make sure the query returns the exact list of columns.")));
7321 newnulls[fnum] = isnull;
7328 if (strict_multiassignment_level && anum < td_natts)
7331 while (anum < td_natts &&
7335 if (anum < td_natts)
7336 ereport(strict_multiassignment_level,
7337 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7338 errmsg(
"number of source and target fields in assignment does not match"),
7341 "strict_multi_assignment",
7342 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7344 errhint(
"Make sure the query returns the exact list of columns.")));
7379 for (fnum = 0; fnum < row->
nfields; fnum++)
7389 while (anum < td_natts &&
7393 if (anum < td_natts)
7396 isnull = nulls[anum];
7406 valtype = UNKNOWNOID;
7409 if (strict_multiassignment_level)
7410 ereport(strict_multiassignment_level,
7411 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7412 errmsg(
"number of source and target fields in assignment does not match"),
7415 "strict_multi_assignment",
7416 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7418 errhint(
"Make sure the query returns the exact list of columns.")));
7422 value, isnull, valtype, valtypmod);
7429 if (strict_multiassignment_level && anum < td_natts)
7431 while (anum < td_natts &&
7435 if (anum < td_natts)
7436 ereport(strict_multiassignment_level,
7437 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7438 errmsg(
"number of source and target fields in assignment does not match"),
7441 "strict_multi_assignment",
7442 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7444 errhint(
"Make sure the query returns the exact list of columns.")));
7465 if (dst_tupdesc->
natts != src_tupdesc->
natts)
7468 for (
i = 0;
i < dst_tupdesc->
natts;
i++)
7473 if (dattr->attisdropped != sattr->attisdropped)
7475 if (!dattr->attisdropped)
7478 if (dattr->atttypid != sattr->atttypid ||
7479 (dattr->atttypmod >= 0 &&
7480 dattr->atttypmod != sattr->atttypmod))
7486 if (dattr->attlen != sattr->attlen ||
7487 dattr->attalign != sattr->attalign)
7508 int natts = tupdesc->
natts;
7520 for (
i = 0;
i < natts;
i++)
7532 &fieldtypeid, &fieldtypmod,
7533 &dvalues[
i], &nulls[
i]);
7614 if (erh == rec->
erh)
7768 (tupType != RECORDOID ||
7830 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
7832 errdetail(
"The tuple structure of a not-yet-assigned record is indeterminate.")));
7895 if (valtype != reqtype ||
7896 (valtypmod != reqtypmod && reqtypmod != -1))
7900 reqtype, reqtypmod);
7920 reqtype, reqtypmod);
8027 placeholder->
typeId = srctype;
8028 placeholder->typeMod = srctypmod;
8046 if (srctype == UNKNOWNOID || srctype == RECORDOID)
8050 (
Node *) placeholder, srctype,
8063 if (cast_expr == NULL)
8067 iocoerce->
arg = (
Expr *) placeholder;
8072 cast_expr = (
Node *) iocoerce;
8073 if (dsttypmod != -1)
8086 cast_expr = cast_cexpr->
expr;
8255 if (query->hasAggs ||
8256 query->hasWindowFuncs ||
8257 query->hasTargetSRFs ||
8258 query->hasSubLinks ||
8324 plan->righttree == NULL &&
8325 plan->initPlan == NULL &&
8326 plan->qual == NULL &&
8333 plan->righttree == NULL &&
8334 plan->initPlan == NULL &&
8335 plan->qual == NULL);
8346 elog(
ERROR,
"unexpected plan node type: %d",
8451 if (context.
count == 1)
8475 fargs = fexpr->
args;
8481 funcid = opexpr->opfuncid;
8482 fargs = opexpr->
args;
8512 req.
type = T_SupportRequestModifyInPlace;
8556 if (++(context->
count) > 1)
8575 Assert(dno >= 0 && dno < estate->ndatums);
8576 datum = estate->
datums[dno];
8577 switch (datum->
dtype)
8584 (
errcode(ERRCODE_ERROR_IN_ASSIGNMENT),
8585 errmsg(
"variable \"%s\" is declared CONSTANT",
8670 "PL/pgSQL simple expressions");
8793 Datum newvalue,
bool isnull,
bool freeable)
8827 newvalue =
datumCopy(detoasted,
false, -1);
8843 var->
value = newvalue;
8930 if (prm->
ptype == UNKNOWNOID)
8939 prm->
ptype = TEXTOID;
8976 const char *portalname,
8992 query =
exec_eval_expr(estate, dynquery, &isnull, &restype, &restypmod);
8995 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
8996 errmsg(
"query string argument of EXECUTE is null")));
9013 options.cursorOptions = cursorOptions;
9019 elog(
ERROR,
"could not open implicit cursor for query \"%s\": %s",
9061 ¶mtypeid, ¶mtypmod,
9062 ¶mdatum, ¶misnull);
9065 paramno > 0 ?
", " :
"",
9082 return paramstr.
data;
9104 for (paramno = 0; paramno < paramLI->
numParams; paramno++)
9114 paramno > 0 ?
", " :
"",
9129 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, int64 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)
#define palloc_array(type, count)
#define palloc0_object(type)
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 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)(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::@57::@71 cparam
ExecEvalSubroutine paramfunc
union ExprEvalStep::@57 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
static bool VARATT_IS_EXTERNAL_EXPANDED_RW(const void *PTR)
static bool VARATT_IS_EXTERNAL_NON_EXPANDED(const void *PTR)
static bool VARATT_IS_EXTERNAL_EXPANDED(const void *PTR)
static bool VARATT_IS_EXTERNAL_EXPANDED_RO(const void *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