MCPcopy Create free account
hub / github.com/apache/cloudberry / exec_stmt_case

Function exec_stmt_case

src/pl/plpgsql/src/pl_exec.c:2499–2578  ·  view source on GitHub ↗

----------- * exec_stmt_case *----------- */

Source from the content-addressed store, hash-verified

2497 *-----------
2498 */
2499static int
2500exec_stmt_case(PLpgSQL_execstate *estate, PLpgSQL_stmt_case *stmt)
2501{
2502 PLpgSQL_var *t_var = NULL;
2503 bool isnull;
2504 ListCell *l;
2505
2506 if (stmt->t_expr != NULL)
2507 {
2508 /* simple case */
2509 Datum t_val;
2510 Oid t_typoid;
2511 int32 t_typmod;
2512
2513 t_val = exec_eval_expr(estate, stmt->t_expr,
2514 &isnull, &t_typoid, &t_typmod);
2515
2516 t_var = (PLpgSQL_var *) estate->datums[stmt->t_varno];
2517
2518 /*
2519 * When expected datatype is different from real, change it. Note that
2520 * what we're modifying here is an execution copy of the datum, so
2521 * this doesn't affect the originally stored function parse tree. (In
2522 * theory, if the expression datatype keeps changing during execution,
2523 * this could cause a function-lifespan memory leak. Doesn't seem
2524 * worth worrying about though.)
2525 */
2526 if (t_var->datatype->typoid != t_typoid ||
2527 t_var->datatype->atttypmod != t_typmod)
2528 t_var->datatype = plpgsql_build_datatype(t_typoid,
2529 t_typmod,
2530 estate->func->fn_input_collation,
2531 NULL);
2532
2533 /* now we can assign to the variable */
2534 exec_assign_value(estate,
2535 (PLpgSQL_datum *) t_var,
2536 t_val,
2537 isnull,
2538 t_typoid,
2539 t_typmod);
2540
2541 exec_eval_cleanup(estate);
2542 }
2543
2544 /* Now search for a successful WHEN clause */
2545 foreach(l, stmt->case_when_list)
2546 {
2547 PLpgSQL_case_when *cwt = (PLpgSQL_case_when *) lfirst(l);
2548 bool value;
2549
2550 value = exec_eval_boolean(estate, cwt->expr, &isnull);
2551 exec_eval_cleanup(estate);
2552 if (!isnull && value)
2553 {
2554 /* Found it */
2555
2556 /* We can now discard any value we had for the temp variable */

Callers 1

exec_stmtsFunction · 0.85

Calls 11

exec_eval_exprFunction · 0.85
plpgsql_build_datatypeFunction · 0.85
exec_assign_valueFunction · 0.85
exec_eval_cleanupFunction · 0.85
exec_eval_booleanFunction · 0.85
assign_simple_varFunction · 0.85
exec_stmtsFunction · 0.85
foreachFunction · 0.50
errcodeFunction · 0.50
errmsgFunction · 0.50
errhintFunction · 0.50

Tested by

no test coverage detected