1972
MariaDBWARNINGNotableDataHIGH confidence

Truncated incorrect value

Production Risk

Medium — data is silently truncated in non-strict mode.

What this means

A value was silently truncated when assigned to a column or variable because it exceeded the allowed length or range. In strict SQL mode this is promoted to an error.

Why it happens
  1. 1String value longer than the target column's maximum length.
  2. 2Numeric value out of range for the target column type.
How to reproduce
trigger — this will error
trigger — this will error
SET @x = CAST('hello_world_too_long' AS CHAR(5));

expected output

Warning 1292: Truncated incorrect CHAR(5) value: 'hello_world_too_long'

Fix 1

Use LEFT() to explicitly truncate strings

Use LEFT() to explicitly truncate strings
SET @x = LEFT('hello_world_too_long', 5);

Why this works

Explicit truncation makes the intent clear and avoids unexpected data loss.

Fix 2

Widen the target column

Widen the target column
ALTER TABLE t MODIFY col VARCHAR(50);

Why this works

Increase the column size to accommodate the actual data length.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 1972 ER_TRUNCATED_WRONG_VALUE

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

← All MariaDB errors