2004
MariaDBERRORNotableQueryHIGH confidence

Only constants are allowed here

Production Risk

Low — statement is rejected.

What this means

A SET statement or similar construct requires a constant value, but a non-constant expression or column reference was provided.

Why it happens
  1. 1Using a column reference or subquery where a constant is required.
  2. 2Dynamic expression in a SET context that only accepts literals.
How to reproduce
trigger — this will error
trigger — this will error
SET @var = col_name; -- col_name is not a constant

expected output

ERROR 2004 (HY000): You may only use constant expressions in this context.

Fix

Use a constant literal or a user variable

Use a constant literal or a user variable
SET @var = 42;

Why this works

Only literal values and session variables are accepted in this context.

Sources
Official documentation ↗

MySQL 8.0 — 2004 ER_SET_CONSTANTS_ONLY

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

← All MariaDB errors