1445
MariaDBERRORNotableStored RoutinesHIGH confidence

Cannot set autocommit from a stored function or trigger

Production Risk

Low — the routine will fail; restructure transaction management.

What this means

ER_SP_CANT_SET_AUTOCOMMIT (1445, SQLSTATE HY000) is raised when a stored function or trigger attempts to change the autocommit setting, which is not permitted in those contexts.

Why it happens
  1. 1SET autocommit = 0 or SET autocommit = 1 inside a stored function or trigger
How to reproduce
trigger — this will error
trigger — this will error
CREATE FUNCTION my_func() RETURNS INT
BEGIN
  SET autocommit = 0;  -- Not allowed in functions/triggers
  RETURN 1;
END;

expected output

ERROR 1445 (HY000): Not allowed to set autocommit from a stored function or trigger

Fix

Set autocommit at the session level before calling the routine

Set autocommit at the session level before calling the routine
SET autocommit = 0;
CALL my_proc();
COMMIT;

Why this works

Transaction control must be managed at the session level, not inside stored functions or triggers.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1445 ER_SP_CANT_SET_AUTOCOMMIT

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

← All MariaDB errors