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

Function exec_stmt_fori

src/pl/plpgsql/src/pl_exec.c:2639–2772  ·  view source on GitHub ↗

---------- * exec_stmt_fori Iterate an integer variable * from a lower to an upper value * incrementing or decrementing by the BY value * ---------- */

Source from the content-addressed store, hash-verified

2637 * ----------
2638 */
2639static int
2640exec_stmt_fori(PLpgSQL_execstate *estate, PLpgSQL_stmt_fori *stmt)
2641{
2642 PLpgSQL_var *var;
2643 Datum value;
2644 bool isnull;
2645 Oid valtype;
2646 int32 valtypmod;
2647 int32 loop_value;
2648 int32 end_value;
2649 int32 step_value;
2650 bool found = false;
2651 int rc = PLPGSQL_RC_OK;
2652
2653 var = (PLpgSQL_var *) (estate->datums[stmt->var->dno]);
2654
2655 /*
2656 * Get the value of the lower bound
2657 */
2658 value = exec_eval_expr(estate, stmt->lower,
2659 &isnull, &valtype, &valtypmod);
2660 value = exec_cast_value(estate, value, &isnull,
2661 valtype, valtypmod,
2662 var->datatype->typoid,
2663 var->datatype->atttypmod);
2664 if (isnull)
2665 ereport(ERROR,
2666 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2667 errmsg("lower bound of FOR loop cannot be null")));
2668 loop_value = DatumGetInt32(value);
2669 exec_eval_cleanup(estate);
2670
2671 /*
2672 * Get the value of the upper bound
2673 */
2674 value = exec_eval_expr(estate, stmt->upper,
2675 &isnull, &valtype, &valtypmod);
2676 value = exec_cast_value(estate, value, &isnull,
2677 valtype, valtypmod,
2678 var->datatype->typoid,
2679 var->datatype->atttypmod);
2680 if (isnull)
2681 ereport(ERROR,
2682 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
2683 errmsg("upper bound of FOR loop cannot be null")));
2684 end_value = DatumGetInt32(value);
2685 exec_eval_cleanup(estate);
2686
2687 /*
2688 * Get the step value
2689 */
2690 if (stmt->step)
2691 {
2692 value = exec_eval_expr(estate, stmt->step,
2693 &isnull, &valtype, &valtypmod);
2694 value = exec_cast_value(estate, value, &isnull,
2695 valtype, valtypmod,
2696 var->datatype->typoid,

Callers 1

exec_stmtsFunction · 0.85

Calls 10

exec_eval_exprFunction · 0.85
exec_cast_valueFunction · 0.85
DatumGetInt32Function · 0.85
exec_eval_cleanupFunction · 0.85
assign_simple_varFunction · 0.85
Int32GetDatumFunction · 0.85
exec_stmtsFunction · 0.85
exec_set_foundFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected