1424
MariaDBerrorstored-procedureshigh confidence

Recursive stored functions and triggers are not allowed

Production Risk

Low — function/trigger fails; no data changed.

What this means

A stored function or trigger attempted to call itself recursively, which is not allowed.

Why it happens
  1. 1Function calling itself directly
  2. 2Trigger on table T fires a statement that modifies T, causing the trigger to fire again
How to reproduce
trigger — this will error
trigger — this will error
CREATE FUNCTION f(n INT) RETURNS INT DETERMINISTIC RETURN IF(n<=1, 1, f(n-1)*n);

expected output

ERROR 1424 (HY000): Recursive stored functions and triggers are not allowed

Fix 1

Use an iterative approach with a loop

Why this works

Replace recursion with an explicit loop inside a procedure.

Fix 2

For recursive procedures, increase max_sp_recursion_depth

For recursive procedures, increase max_sp_recursion_depth
SET SESSION max_sp_recursion_depth = 10;

Why this works

Stored procedures (not functions) can be recursive if max_sp_recursion_depth > 0.

What not to do

Version notes

Sources
Official documentation ↗

MySQL 8.0 — 1424 ER_SP_NO_RECURSION

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MariaDB errors