47 #include "utils/fmgroids.h"
131 #define get_eval_mcontext(estate) \
132 ((estate)->eval_econtext->ecxt_per_tuple_memory)
133 #define eval_mcontext_alloc(estate, sz) \
134 MemoryContextAlloc(get_eval_mcontext(estate), sz)
135 #define eval_mcontext_alloc0(estate, sz) \
136 MemoryContextAllocZero(get_eval_mcontext(estate), sz)
208 #define LOOP_RC_PROCESSING(looplabel, exit_action) \
209 if (rc == PLPGSQL_RC_RETURN) \
214 else if (rc == PLPGSQL_RC_EXIT) \
216 if (estate->exitlabel == NULL) \
219 rc = PLPGSQL_RC_OK; \
222 else if ((looplabel) != NULL && \
223 strcmp(looplabel, estate->exitlabel) == 0) \
226 estate->exitlabel = NULL; \
227 rc = PLPGSQL_RC_OK; \
236 else if (rc == PLPGSQL_RC_CONTINUE) \
238 if (estate->exitlabel == NULL) \
241 rc = PLPGSQL_RC_OK; \
243 else if ((looplabel) != NULL && \
244 strcmp(looplabel, estate->exitlabel) == 0) \
247 estate->exitlabel = NULL; \
248 rc = PLPGSQL_RC_OK; \
257 Assert(rc == PLPGSQL_RC_OK)
335 EState *simple_eval_estate,
382 Portal portal,
bool prefetch_ok);
386 int paramid,
bool speculative,
390 Datum *resv,
bool *resnull);
443 Datum newvalue,
bool isnull,
bool freeable);
452 const char *portalname,
int cursorOptions);
482 EState *simple_eval_estate,
496 simple_eval_estate, simple_eval_resowner);
504 plerrcontext.
arg = &estate;
616 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
627 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
628 errmsg(
"control reached end of function without RETURN")));
645 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
646 errmsg(
"set-valued function called in context that cannot accept a set")));
650 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
651 errmsg(
"materialize mode required, but it is not allowed in this context")));
733 elog(
ERROR,
"return type must be a row type");
784 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
833 gettext_noop(
"returned record type does not match expected record type"));
897 gettext_noop(
"returned record type does not match expected record type"));
943 plerrcontext.
arg = &estate;
1002 for (
int i = 0;
i < tupdesc->
natts;
i++)
1003 if (
TupleDescAttr(tupdesc,
i)->attgenerated == ATTRIBUTE_GENERATED_STORED)
1017 elog(
ERROR,
"unrecognized trigger action: not INSERT, DELETE, or UPDATE");
1034 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
1045 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
1046 errmsg(
"control reached end of trigger procedure without RETURN")));
1053 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1054 errmsg(
"trigger procedure cannot return a set")));
1093 gettext_noop(
"returned row structure does not match the structure of the triggering table"));
1121 gettext_noop(
"returned row structure does not match the structure of the triggering table"));
1138 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
1178 plerrcontext.
arg = &estate;
1192 ((*plpgsql_plugin_ptr)->func_beg) (&estate, func);
1203 (
errcode(ERRCODE_S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT),
1204 errmsg(
"control reached end of trigger procedure without RETURN")));
1213 ((*plpgsql_plugin_ptr)->func_end) (&estate, func);
1262 errcontext(
"PL/pgSQL function %s line %d %s",
1278 else if (estate->
err_stmt != NULL && err_lineno > 0)
1281 errcontext(
"PL/pgSQL function %s line %d at %s",
1300 int ndatums = estate->
ndatums;
1316 ws_next = workspace;
1320 outdatums = estate->
datums;
1321 for (
i = 0;
i < ndatums;
i++)
1327 switch (indatum->
dtype)
1359 outdatums[
i] = outdatum;
1392 elog(
ERROR,
"trigger promise is not in a trigger function");
1401 elog(
ERROR,
"trigger promise is not in a trigger function");
1409 elog(
ERROR,
"unrecognized trigger execution time: not BEFORE, AFTER, or INSTEAD OF");
1414 elog(
ERROR,
"trigger promise is not in a trigger function");
1420 elog(
ERROR,
"unrecognized trigger event type: not ROW or STATEMENT");
1425 elog(
ERROR,
"trigger promise is not in a trigger function");
1435 elog(
ERROR,
"unrecognized trigger action: not INSERT, DELETE, UPDATE, or TRUNCATE");
1440 elog(
ERROR,
"trigger promise is not in a trigger function");
1448 elog(
ERROR,
"trigger promise is not in a trigger function");
1457 elog(
ERROR,
"trigger promise is not in a trigger function");
1466 elog(
ERROR,
"trigger promise is not in a trigger function");
1474 elog(
ERROR,
"trigger promise is not in a trigger function");
1488 for (
i = 0;
i < nelems;
i++)
1497 -1,
false, TYPALIGN_INT)),
1508 elog(
ERROR,
"event trigger promise is not in an event trigger function");
1514 elog(
ERROR,
"event trigger promise is not in an event trigger function");
1537 "PLpgSQL per-statement data",
1584 for (; cond != NULL; cond = cond->
next)
1593 if (sqlerrstate == 0)
1595 if (edata->
sqlerrcode != ERRCODE_QUERY_CANCELED &&
1629 ((*plpgsql_plugin_ptr)->stmt_beg) (estate, (
PLpgSQL_stmt *) block);
1637 ((*plpgsql_plugin_ptr)->stmt_end) (estate, (
PLpgSQL_stmt *) block);
1652 volatile int rc = -1;
1677 switch (datum->
dtype)
1811 resTypByVal, resTypLen);
1962 if (block->
label == NULL)
2008 ((*plpgsql_plugin_ptr)->stmt_beg) (estate,
stmt);
2012 switch (
stmt->cmd_type)
2131 ((*plpgsql_plugin_ptr)->stmt_end) (estate,
stmt);
2196 if (expr->
plan == NULL)
2209 if (
stmt->is_call &&
stmt->target == NULL)
2226 options.allow_nonatomic =
true;
2232 elog(
ERROR,
"SPI_execute_plan_extended failed executing query \"%s\": %s",
2237 if (before_lxid != after_lxid)
2257 elog(
ERROR,
"DO statement returned a row");
2262 elog(
ERROR,
"procedure call returned more than one row");
2300 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2303 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2307 elog(
ERROR,
"query for CALL statement is not a CallStmt");
2309 funcexpr =
stmt->funcexpr;
2314 elog(
ERROR,
"cache lookup failed for function %u",
2333 row->
refname =
"(unnamed row)";
2345 for (
i = 0;
i < numargs;
i++)
2348 (argmodes[
i] == PROARGMODE_INOUT ||
2349 argmodes[
i] == PROARGMODE_OUT))
2362 row->
varnos[nfields++] = dno;
2367 if (argnames && argnames[
i] && argnames[
i][0])
2369 (
errcode(ERRCODE_SYNTAX_ERROR),
2370 errmsg(
"procedure parameter \"%s\" is an output parameter but corresponding argument is not writable",
2374 (
errcode(ERRCODE_SYNTAX_ERROR),
2375 errmsg(
"procedure parameter %d is an output parameter but corresponding argument is not writable",
2408 (
errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER),
2409 errmsg(
"GET STACKED DIAGNOSTICS cannot be used outside an exception handler")));
2411 foreach(lc,
stmt->diag_items)
2416 switch (diag_item->
kind)
2421 false, INT8OID, -1);
2482 char *contextstackstr;
2495 elog(
ERROR,
"unrecognized diagnostic item kind: %d",
2520 if (!isnull &&
value)
2523 foreach(lc,
stmt->elsif_list)
2529 if (!isnull &&
value)
2548 if (
stmt->t_expr != NULL)
2556 &isnull, &t_typoid, &t_typmod);
2587 foreach(l,
stmt->case_when_list)
2594 if (!isnull &&
value)
2612 if (!
stmt->have_else)
2614 (
errcode(ERRCODE_CASE_NOT_FOUND),
2615 errmsg(
"case not found"),
2616 errhint(
"CASE statement is missing ELSE part.")));
2663 if (isnull || !
value)
2701 &isnull, &valtype, &valtypmod);
2708 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2709 errmsg(
"lower bound of FOR loop cannot be null")));
2717 &isnull, &valtype, &valtypmod);
2724 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2725 errmsg(
"upper bound of FOR loop cannot be null")));
2735 &isnull, &valtype, &valtypmod);
2742 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2743 errmsg(
"BY value of FOR loop cannot be null")));
2746 if (step_value <= 0)
2748 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2749 errmsg(
"BY value of FOR loop must be greater than zero")));
2764 if (loop_value < end_value)
2769 if (loop_value > end_value)
2795 loop_value -= step_value;
2801 loop_value += step_value;
2858 char *curname = NULL;
2882 (
errcode(ERRCODE_DUPLICATE_CURSOR),
2883 errmsg(
"cursor \"%s\" already in use", curname)));
2893 if (
stmt->argquery != NULL)
2905 (
errcode(ERRCODE_SYNTAX_ERROR),
2906 errmsg(
"arguments given for cursor without arguments")));
2908 memset(&set_args, 0,
sizeof(set_args));
2912 set_args.
into =
true;
2918 elog(
ERROR,
"open cursor failed during argument processing");
2924 (
errcode(ERRCODE_SYNTAX_ERROR),
2925 errmsg(
"arguments required for cursor")));
2931 if (query->
plan == NULL)
2946 elog(
ERROR,
"could not open cursor: %s",
2953 if (curname == NULL)
2978 if (curname == NULL)
3000 Oid loop_var_elem_type;
3006 Oid iterator_result_type;
3007 int32 iterator_result_typmod;
3015 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3016 errmsg(
"FOREACH expression must not be null")));
3030 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3031 errmsg(
"FOREACH expression must yield an array, not type %s",
3047 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
3048 errmsg(
"slice dimension (%d) is out of the valid range 0..%d",
3074 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3075 errmsg(
"FOREACH ... SLICE loop variable must be of an array type")));
3078 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3079 errmsg(
"FOREACH loop variable must not be of an array type")));
3085 if (
stmt->slice > 0)
3088 iterator_result_type = arrtype;
3089 iterator_result_typmod = arrtypmod;
3095 iterator_result_typmod = arrtypmod;
3108 iterator_result_type, iterator_result_typmod);
3111 if (
stmt->slice > 0)
3155 if (
stmt->cond != NULL)
3162 if (isnull ||
value ==
false)
3210 if (
stmt->retvarno >= 0)
3214 switch (retvar->
dtype)
3240 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3241 errmsg(
"cannot return non-composite value from function returning composite type")));
3281 if (
stmt->expr != NULL)
3297 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3298 errmsg(
"cannot return non-composite value from function returning composite type")));
3336 (
errcode(ERRCODE_SYNTAX_ERROR),
3337 errmsg(
"cannot use RETURN NEXT in a non-SETOF function")));
3344 natts = tupdesc->
natts;
3356 if (
stmt->retvarno >= 0)
3360 switch (retvar->
dtype)
3372 bool isNull = var->
isnull;
3377 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3378 errmsg(
"wrong result type supplied in RETURN NEXT")));
3406 if (rec->
erh == NULL)
3416 gettext_noop(
"wrong record type supplied in RETURN NEXT"));
3436 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3437 errmsg(
"wrong record type supplied in RETURN NEXT")));
3448 else if (
stmt->expr)
3472 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3473 errmsg(
"cannot return non-composite value from function returning composite type")));
3480 gettext_noop(
"returned record type does not match expected record type"));
3493 nulldatums = (
Datum *)
3495 nullflags = (
bool *)
3497 memset(nullflags,
true, natts *
sizeof(
bool));
3499 nulldatums, nullflags);
3509 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3510 errmsg(
"wrong result type supplied in RETURN NEXT")));
3528 (
errcode(ERRCODE_SYNTAX_ERROR),
3529 errmsg(
"RETURN NEXT must have a parameter")));
3556 (
errcode(ERRCODE_SYNTAX_ERROR),
3557 errmsg(
"cannot use RETURN QUERY in a non-SETOF function")));
3575 gettext_noop(
"structure of query does not match function result type"));
3578 if (
stmt->query != NULL)
3588 if (expr->
plan == NULL)
3602 options.must_return_tuples =
true;
3607 elog(
ERROR,
"SPI_execute_plan_extended failed executing query \"%s\": %s",
3626 &isnull, &restype, &restypmod);
3629 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3630 errmsg(
"query string argument of EXECUTE is null")));
3645 options.must_return_tuples =
true;
3650 elog(
ERROR,
"SPI_execute_extended failed executing query \"%s\": %s",
3680 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3681 errmsg(
"set-valued function called in context that cannot accept a set")));
3686 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3687 errmsg(
"materialize mode required, but it is not allowed in this context")));
3710 #define SET_RAISE_OPTION_TEXT(opt, name) \
3714 (errcode(ERRCODE_SYNTAX_ERROR), \
3715 errmsg("RAISE option already specified: %s", \
3717 opt = MemoryContextStrdup(stmt_mcontext, extval); \
3728 char *condname = NULL;
3729 char *err_message = NULL;
3730 char *err_detail = NULL;
3731 char *err_hint = NULL;
3732 char *err_column = NULL;
3733 char *err_constraint = NULL;
3734 char *err_datatype = NULL;
3735 char *err_table = NULL;
3736 char *err_schema = NULL;
3741 if (
stmt->condname == NULL &&
stmt->message == NULL &&
3748 (
errcode(ERRCODE_STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER),
3749 errmsg(
"RAISE without parameters cannot be used outside an exception handler")));
3775 for (cp =
stmt->message; *cp; cp++)
3797 if (current_param == NULL)
3798 elog(
ERROR,
"unexpected RAISE parameter list length");
3813 current_param =
lnext(
stmt->params, current_param);
3821 if (current_param != NULL)
3822 elog(
ERROR,
"unexpected RAISE parameter list length");
3824 err_message = ds.
data;
3827 foreach(lc,
stmt->options)
3842 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
3843 errmsg(
"RAISE statement option cannot be null")));
3852 (
errcode(ERRCODE_SYNTAX_ERROR),
3853 errmsg(
"RAISE option already specified: %s",
3890 if (err_code == 0 &&
stmt->elog_level >=
ERROR)
3891 err_code = ERRCODE_RAISE_EXCEPTION;
3894 if (err_message == NULL)
3898 err_message = condname;
3910 (err_code ?
errcode(err_code) : 0,
3913 (err_hint != NULL) ?
errhint(
"%s", err_hint) : 0,
3914 (err_column != NULL) ?
3916 (err_constraint != NULL) ?
3918 (err_datatype != NULL) ?
3920 (err_table != NULL) ?
3922 (err_schema != NULL) ?
3948 if (isnull || !
value)
3950 char *message = NULL;
3952 if (
stmt->message != NULL)
3959 &isnull, &
typeid, &typmod);
3966 (
errcode(ERRCODE_ASSERT_FAILURE),
3968 errmsg(
"assertion failed")));
3982 EState *simple_eval_estate,
3990 estate->
func = func;
4050 if (simple_eval_estate)
4078 if (simple_eval_resowner)
4123 if ((*plpgsql_plugin_ptr)->func_setup)
4124 ((*plpgsql_plugin_ptr)->func_setup) (estate, func);
4190 options.parserSetupArg = (
void *) expr;
4192 options.cursorOptions = cursorOptions;
4195 elog(
ERROR,
"SPI_prepare_extended failed for \"%s\": %s",
4221 int too_many_rows_level = 0;
4224 too_many_rows_level =
ERROR;
4226 too_many_rows_level =
WARNING;
4232 if (expr->
plan == NULL)
4235 if (!
stmt->mod_stmt_set)
4239 stmt->mod_stmt =
false;
4250 if (plansource->
commandTag == CMDTAG_INSERT ||
4255 stmt->mod_stmt =
true;
4259 stmt->mod_stmt_set =
true;
4281 if (
stmt->strict ||
stmt->mod_stmt || too_many_rows_level)
4338 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4339 errmsg(
"cannot COPY to/from client in PL/pgSQL")));
4344 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4345 errmsg(
"unsupported transaction command in PL/pgSQL")));
4349 elog(
ERROR,
"SPI_execute_plan_with_paramlist failed executing query \"%s\": %s",
4367 (
errcode(ERRCODE_SYNTAX_ERROR),
4368 errmsg(
"INTO used with a command that cannot return data")));
4390 (
errcode(ERRCODE_NO_DATA_FOUND),
4391 errmsg(
"query returned no rows"),
4399 if (n > 1 && (
stmt->strict ||
stmt->mod_stmt || too_many_rows_level))
4409 errlevel = (
stmt->strict ||
stmt->mod_stmt) ?
ERROR : too_many_rows_level;
4412 (
errcode(ERRCODE_TOO_MANY_ROWS),
4413 errmsg(
"query returned more than one row"),
4415 errhint(
"Make sure the query returns a single row, or use LIMIT 1.")));
4430 (
errcode(ERRCODE_SYNTAX_ERROR),
4431 errmsg(
"query has no destination for result data"),
4432 (rc ==
SPI_OK_SELECT) ?
errhint(
"If you want to discard the results of a SELECT, use PERFORM instead.") : 0));
4465 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4466 errmsg(
"query string argument of EXECUTE is null")));
4520 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4521 errmsg(
"EXECUTE of SELECT ... INTO is not implemented"),
4522 errhint(
"You might want to use EXECUTE ... INTO or EXECUTE CREATE TABLE ... AS instead.")));
4528 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4529 errmsg(
"cannot COPY to/from client in PL/pgSQL")));
4534 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4535 errmsg(
"EXECUTE of transaction commands is not implemented")));
4539 elog(
ERROR,
"SPI_execute_extended failed executing query \"%s\": %s",
4557 (
errcode(ERRCODE_SYNTAX_ERROR),
4558 errmsg(
"INTO used with a command that cannot return data")));
4580 (
errcode(ERRCODE_NO_DATA_FOUND),
4581 errmsg(
"query returned no rows"),
4589 if (n > 1 &&
stmt->strict)
4599 (
errcode(ERRCODE_TOO_MANY_ROWS),
4600 errmsg(
"query returned more than one row"),
4666 char *curname = NULL;
4689 (
errcode(ERRCODE_DUPLICATE_CURSOR),
4690 errmsg(
"cursor \"%s\" already in use", curname)));
4697 if (
stmt->query != NULL)
4706 query =
stmt->query;
4707 if (query->
plan == NULL)
4710 else if (
stmt->dynquery != NULL)
4720 stmt->cursor_options);
4730 if (curname == NULL)
4747 if (
stmt->argquery != NULL)
4759 (
errcode(ERRCODE_SYNTAX_ERROR),
4760 errmsg(
"arguments given for cursor without arguments")));
4762 memset(&set_args, 0,
sizeof(set_args));
4766 set_args.
into =
true;
4772 elog(
ERROR,
"open cursor failed during argument processing");
4778 (
errcode(ERRCODE_SYNTAX_ERROR),
4779 errmsg(
"arguments required for cursor")));
4783 if (query->
plan == NULL)
4799 elog(
ERROR,
"could not open cursor: %s",
4806 if (curname == NULL)
4830 long how_many =
stmt->how_many;
4844 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4845 errmsg(
"cursor variable \"%s\" is null", curvar->
refname)));
4855 (
errcode(ERRCODE_UNDEFINED_CURSOR),
4856 errmsg(
"cursor \"%s\" does not exist", curname)));
4868 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4869 errmsg(
"relative or absolute cursor position is null")));
4932 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
4933 errmsg(
"cursor variable \"%s\" is null", curvar->
refname)));
4943 (
errcode(ERRCODE_UNDEFINED_CURSOR),
4944 errmsg(
"cursor \"%s\" does not exist", curname)));
5019 if (expr->
plan == NULL)
5085 switch (target->
dtype)
5106 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5107 errmsg(
"null value cannot be assigned to variable \"%s\" declared NOT NULL",
5156 if (var->
value != newvalue || var->
isnull || isNull)
5182 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5183 errmsg(
"cannot assign non-composite value to a row variable")));
5201 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
5202 errmsg(
"null value cannot be assigned to variable \"%s\" declared NOT NULL",
5214 (
errcode(ERRCODE_DATATYPE_MISMATCH),
5215 errmsg(
"cannot assign non-composite value to a record variable")));
5256 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5257 errmsg(
"record \"%s\" has no field \"%s\"",
5265 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
5266 errmsg(
"cannot assign to system column \"%s\"",
5316 switch (datum->
dtype)
5342 elog(
ERROR,
"row variable has no tupdesc");
5348 elog(
ERROR,
"row not compatible with its own tupdesc");
5361 if (rec->
erh == NULL)
5429 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5430 errmsg(
"record \"%s\" has no field \"%s\"",
5463 switch (datum->
dtype)
5503 if (rec->
erh == NULL)
5516 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5517 errmsg(
"record \"%s\" has no field \"%s\"",
5547 switch (datum->
dtype)
5594 if (rec->
erh == NULL)
5607 (
errcode(ERRCODE_UNDEFINED_COLUMN),
5608 errmsg(
"record \"%s\" has no field \"%s\"",
5646 exprdatum =
exec_eval_expr(estate, expr, isNull, &exprtypeid, &exprtypmod);
5648 exprtypeid, exprtypmod,
5669 exprdatum =
exec_eval_expr(estate, expr, isNull, &exprtypeid, &exprtypmod);
5671 exprtypeid, exprtypmod,
5697 if (expr->
plan == NULL)
5705 &result, isNull, rettype, rettypmod))
5714 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
5715 errmsg(
"query did not return data"),
5723 (
errcode(ERRCODE_SYNTAX_ERROR),
5725 "query returned %d columns",
5734 *rettype = attr->atttypid;
5735 *rettypmod = attr->atttypmod;
5751 (
errcode(ERRCODE_CARDINALITY_VIOLATION),
5752 errmsg(
"query returned more than one row"),
5785 if (expr->
plan == NULL)
5789 if (portalP == NULL)
5802 if (portalP != NULL)
5807 if (*portalP == NULL)
5808 elog(
ERROR,
"could not open implicit cursor for query \"%s\": %s",
5827 (
errcode(ERRCODE_SYNTAX_ERROR),
5828 errmsg(
"query is SELECT INTO, but it should be plain SELECT"),
5832 (
errcode(ERRCODE_SYNTAX_ERROR),
5833 errmsg(
"query is not a SELECT"),
5853 Portal portal,
bool prefetch_ok)
5860 bool tupdescs_match =
true;
5881 prefetch_ok =
false;
5911 for (
i = 0;
i < n;
i++)
6044 void *save_setup_arg;
6311 int paramid,
bool speculative,
6323 Assert(dno >= 0 && dno < params->numParams);
6331 datum = estate->
datums[dno];
6347 else if (speculative)
6349 switch (datum->
dtype)
6374 if (rec->
erh == NULL)
6411 &prm->
ptype, &prmtypmod,
6439 Datum *resv,
bool *resnull)
6453 Assert(dno >= 0 && dno < estate->ndatums);
6456 datum = estate->
datums[dno];
6499 scratch.
d.
cparam.paramarg = NULL;
6517 int dno = op->
d.
cparam.paramid - 1;
6523 Assert(dno >= 0 && dno < estate->ndatums);
6549 int dno = op->
d.
cparam.paramid - 1;
6555 Assert(dno >= 0 && dno < estate->ndatums);
6586 int dno = op->
d.
cparam.paramid - 1;
6594 Assert(dno >= 0 && dno < estate->ndatums);
6625 (
errcode(ERRCODE_UNDEFINED_COLUMN),
6626 errmsg(
"record \"%s\" has no field \"%s\"",
6639 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6640 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6658 int dno = op->
d.
cparam.paramid - 1;
6666 Assert(dno >= 0 && dno < estate->ndatums);
6669 datum = estate->
datums[dno];
6673 &datumtype, &datumtypmod,
6679 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6680 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6698 int dno = op->
d.
cparam.paramid - 1;
6706 Assert(dno >= 0 && dno < estate->ndatums);
6709 datum = estate->
datums[dno];
6713 &datumtype, &datumtypmod,
6719 (
errcode(ERRCODE_DATATYPE_MISMATCH),
6720 errmsg(
"type of parameter %d (%s) does not match that when preparing the plan (%s)",
6762 if (tupdesc == NULL)
6833 int td_natts = tupdesc->
natts;
6836 Datum values_local[64];
6837 bool nulls_local[64];
6844 if (td_natts <=
lengthof(values_local))
6847 nulls = nulls_local;
6854 td_natts * (
sizeof(
Datum) +
sizeof(
bool)));
6856 nulls = (
bool *) (
chunk + td_natts *
sizeof(
Datum));
6916 if (typentry->
typtype == TYPTYPE_DOMAIN)
6919 if (typentry->
tupDesc == NULL)
6926 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
6927 errmsg(
"type %s is not composite",
7027 int td_natts = tupdesc ? tupdesc->
natts : 0;
7030 int strict_multiassignment_level = 0;
7036 if (tupdesc != NULL)
7039 strict_multiassignment_level =
ERROR;
7041 strict_multiassignment_level =
WARNING;
7049 Datum newvalues_local[64];
7050 bool newnulls_local[64];
7065 if (var_tupdesc != tupdesc)
7067 int vtd_natts = var_tupdesc->
natts;
7076 if (vtd_natts <=
lengthof(newvalues_local))
7078 newvalues = newvalues_local;
7079 newnulls = newnulls_local;
7086 vtd_natts * (
sizeof(
Datum) +
sizeof(
bool)));
7088 newnulls = (
bool *) (
chunk + vtd_natts *
sizeof(
Datum));
7093 for (fnum = 0; fnum < vtd_natts; fnum++)
7101 if (attr->attisdropped)
7107 while (anum < td_natts &&
7111 if (anum < td_natts)
7114 isnull = nulls[anum];
7124 valtype = UNKNOWNOID;
7128 if (strict_multiassignment_level)
7129 ereport(strict_multiassignment_level,
7130 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7131 errmsg(
"number of source and target fields in assignment does not match"),
7134 "strict_multi_assignment",
7135 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7137 errhint(
"Make sure the query returns the exact list of columns.")));
7148 newnulls[fnum] = isnull;
7155 if (strict_multiassignment_level && anum < td_natts)
7158 while (anum < td_natts &&
7162 if (anum < td_natts)
7163 ereport(strict_multiassignment_level,
7164 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7165 errmsg(
"number of source and target fields in assignment does not match"),
7168 "strict_multi_assignment",
7169 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7171 errhint(
"Make sure the query returns the exact list of columns.")));
7206 for (fnum = 0; fnum < row->
nfields; fnum++)
7216 while (anum < td_natts &&
7220 if (anum < td_natts)
7223 isnull = nulls[anum];
7233 valtype = UNKNOWNOID;
7236 if (strict_multiassignment_level)
7237 ereport(strict_multiassignment_level,
7238 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7239 errmsg(
"number of source and target fields in assignment does not match"),
7242 "strict_multi_assignment",
7243 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7245 errhint(
"Make sure the query returns the exact list of columns.")));
7249 value, isnull, valtype, valtypmod);
7256 if (strict_multiassignment_level && anum < td_natts)
7258 while (anum < td_natts &&
7262 if (anum < td_natts)
7263 ereport(strict_multiassignment_level,
7264 (
errcode(ERRCODE_DATATYPE_MISMATCH),
7265 errmsg(
"number of source and target fields in assignment does not match"),
7268 "strict_multi_assignment",
7269 strict_multiassignment_level ==
ERROR ?
"extra_errors" :
7271 errhint(
"Make sure the query returns the exact list of columns.")));
7292 if (dst_tupdesc->
natts != src_tupdesc->
natts)
7295 for (
i = 0;
i < dst_tupdesc->
natts;
i++)
7300 if (dattr->attisdropped != sattr->attisdropped)
7302 if (!dattr->attisdropped)
7305 if (dattr->atttypid != sattr->atttypid ||
7306 (dattr->atttypmod >= 0 &&
7307 dattr->atttypmod != sattr->atttypmod))
7313 if (dattr->attlen != sattr->attlen ||
7314 dattr->attalign != sattr->attalign)
7335 int natts = tupdesc->
natts;
7347 for (
i = 0;
i < natts;
i++)
7359 &fieldtypeid, &fieldtypmod,
7360 &dvalues[
i], &nulls[
i]);
7441 if (erh == rec->
erh)
7595 (tupType != RECORDOID ||
7657 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
7659 errdetail(
"The tuple structure of a not-yet-assigned record is indeterminate.")));
7722 if (valtype != reqtype ||
7723 (valtypmod != reqtypmod && reqtypmod != -1))
7727 reqtype, reqtypmod);
7747 reqtype, reqtypmod);
7854 placeholder->
typeId = srctype;
7855 placeholder->typeMod = srctypmod;
7873 if (srctype == UNKNOWNOID || srctype == RECORDOID)
7877 (
Node *) placeholder, srctype,
7890 if (cast_expr == NULL)
7894 iocoerce->
arg = (
Expr *) placeholder;
7899 cast_expr = (
Node *) iocoerce;
7900 if (dsttypmod != -1)
7913 cast_expr = cast_cexpr->
expr;
8025 if (query->hasAggs ||
8026 query->hasWindowFuncs ||
8027 query->hasTargetSRFs ||
8028 query->hasSubLinks ||
8126 plan->righttree == NULL &&
8127 plan->initPlan == NULL &&
8128 plan->qual == NULL &&
8135 plan->righttree == NULL &&
8136 plan->initPlan == NULL &&
8137 plan->qual == NULL);
8148 elog(
ERROR,
"unexpected plan node type: %d",
8233 fargs = fexpr->
args;
8239 funcid = opexpr->opfuncid;
8240 fargs = opexpr->
args;
8248 F_ARRAY_SUBSCRIPT_HANDLER)
8257 param->
paramid == target_dno + 1)
8275 if (!(funcid == F_ARRAY_APPEND ||
8276 funcid == F_ARRAY_PREPEND))
8294 param->
paramid == target_dno + 1)
8314 Assert(dno >= 0 && dno < estate->ndatums);
8315 datum = estate->
datums[dno];
8316 switch (datum->
dtype)
8323 (
errcode(ERRCODE_ERROR_IN_ASSIGNMENT),
8324 errmsg(
"variable \"%s\" is declared CONSTANT",
8400 "PL/pgSQL simple expressions");
8523 Datum newvalue,
bool isnull,
bool freeable)
8557 newvalue =
datumCopy(detoasted,
false, -1);
8573 var->
value = newvalue;
8660 if (prm->
ptype == UNKNOWNOID)
8669 prm->
ptype = TEXTOID;
8706 const char *portalname,
8722 query =
exec_eval_expr(estate, dynquery, &isnull, &restype, &restypmod);
8725 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
8726 errmsg(
"query string argument of EXECUTE is null")));
8743 options.cursorOptions = cursorOptions;
8749 elog(
ERROR,
"could not open implicit cursor for query \"%s\": %s",
8791 ¶mtypeid, ¶mtypmod,
8792 ¶mdatum, ¶misnull);
8795 paramno > 0 ?
", " :
"",
8812 return paramstr.
data;
8834 for (paramno = 0; paramno < paramLI->
numParams; paramno++)
8844 paramno > 0 ?
", " :
"",
8859 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,...)
int errdetail_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
ErrorContextCallback * error_context_stack
void ReThrowError(ErrorData *edata)
void FlushErrorState(void)
int errhint(const char *fmt,...)
char * unpack_sql_state(int sql_state)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
char * GetErrorContextStack(void)
ErrorData * CopyErrorData(void)
#define ERRCODE_IS_CATEGORY(ec)
#define ERRCODE_TO_CATEGORY(ec)
#define ereport(elevel,...)
ExprState * ExecInitExprWithParams(Expr *node, ParamListInfo ext_params)
void ExprEvalPushStep(ExprState *es, const ExprEvalStep *s)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
void FreeExprContext(ExprContext *econtext, bool isCommit)
EState * CreateExecutorState(void)
ExprContext * CreateExprContext(EState *estate)
void FreeExecutorState(EState *estate)
@ 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_tupdesc(TupleDesc tupdesc, MemoryContext parentcontext)
ExpandedRecordHeader * make_expanded_record_from_typeid(Oid type_id, int32 typmod, 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_exprecord(ExpandedRecordHeader *olderh, 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)
char * get_namespace_name(Oid nspid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Oid get_typcollation(Oid typid)
RegProcedure get_typsubscript(Oid typid, Oid *typelemp)
void MemoryContextReset(MemoryContext context)
MemoryContext TopTransactionContext
void pfree(void *pointer)
void MemoryContextDeleteChildren(MemoryContext context)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
void * MemoryContextAlloc(MemoryContext context, Size size)
char * MemoryContextStrdup(MemoryContext context, const char *string)
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 ListCell * list_head(const List *l)
static void * list_nth(const List *list, int n)
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)
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)
bool CachedPlanIsSimplyValid(CachedPlanSource *plansource, CachedPlan *plan, ResourceOwner owner)
CachedExpression * GetCachedExpression(Node *expr)
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 char * DatumGetCString(Datum X)
static Datum UInt64GetDatum(uint64 X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid 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)
int SPI_execute_plan_with_paramlist(SPIPlanPtr plan, ParamListInfo params, bool read_only, long tcount)
CachedPlan * SPI_plan_get_cached_plan(SPIPlanPtr plan)
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)
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)
const char * SPI_result_code_string(int code)
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)
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)
List * SPI_plan_get_plan_sources(SPIPlanPtr plan)
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
union ExprEvalStep::@54 d
struct ExprEvalStep::@54::@67 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)
#define TupleDescAttr(tupdesc, i)
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
int64 tuplestore_tuple_count(Tuplestorestate *state)
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