1328
MariaDBerrorstored-procedureshigh confidence

Statement not allowed in stored function or trigger

Production Risk

Low — compile-time or runtime error; function/trigger not executed.

What this means

A statement that causes an implicit or explicit commit (e.g. DDL, LOCK TABLES) was used inside a stored function or trigger.

Why it happens
  1. 1Using CREATE TABLE, DROP TABLE, or ALTER TABLE inside a function or trigger
  2. 2Using LOCK TABLES inside a function
How to reproduce
trigger — this will error
trigger — this will error
CREATE FUNCTION f() RETURNS INT BEGIN CREATE TABLE tmp (id INT); RETURN 1; END;

expected output

ERROR 1328 (0A000): Not allowed to return a result set from a function

Fix

Move DDL outside the function/trigger

Why this works

Perform schema changes from application code or a stored procedure, not a function or trigger.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1328 ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG

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

← All MariaDB errors