Common SQL Errors

MySQL Error 1367: ER_ILLEGAL_VALUE_FOR_TYPE - How to Fix and Prevent

Galaxy Team
August 6, 2025

<p>MySQL raises Error 1367 when a literal value cannot be coerced into the target column or variable data type during SQL parsing.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1367 ER_ILLEGAL_VALUE_FOR_TYPE?

<p>MySQL Error 1367: ER_ILLEGAL_VALUE_FOR_TYPE appears when the server meets a date, time, numeric, or enum value that does not match the target data type. Validate and cast the literal or change the column definition to resolve the issue.</p>

Error Highlights

Typical Error Message

Illegal %s '%s' value found during parsing

Error Type

Data Parsing Error

Language

MySQL

Symbol

ER_ILLEGAL_VALUE_FOR_TYPE

Error Code

1367

SQL State

22007

Explanation

Table of Contents

What is MySQL Error 1367 ER_ILLEGAL_VALUE_FOR_TYPE?

MySQL throws Error 1367 with message Illegal %s '%s' value found during parsing when it encounters a literal that cannot be converted to the expected data type. The server halts statement execution and returns SQLSTATE 22007.

The error protects data integrity by blocking inserts, updates, or casts that would otherwise introduce invalid or truncated values.

What Causes This Error?

The parser checks each supplied literal against the column or variable type. If the value is out of range, badly formatted, or not listed in an ENUM set, MySQL reports Error 1367 instead of silently modifying the data.

The most common triggers involve malformed date and time strings, numeric overflow, and enum or set members that are not defined in the schema.

How to Fix MySQL Error 1367: ER_ILLEGAL_VALUE_FOR_TYPE

First confirm the target column type with DESCRIBE or SHOW COLUMNS. Validate the literal matches the accepted format and range. If needed, CAST the value or alter the column definition.

Run the statement again after correcting the value, or enable strict SQL mode adjustments only when you are certain of consequences.

Common Scenarios and Solutions

Invalid date 2024-02-31 in an INSERT will fail; switch to 2024-02-29 or change the column to VARCHAR if you must store free-form text.

Attempting to insert 999999 into a TINYINT column triggers the error; use a larger integer type or reduce the value.

Best Practices to Avoid This Error

Always validate user input, use parameterized queries, and enable SQL_MODE=STRICT_ALL_TABLES in development to surface issues early.

Define ENUM and SET lists carefully and provide fallback handling in application code when an unsupported option is received.

Related Errors and Solutions

Error 1292 Truncated Incorrect Value arises for similar data coercion problems. Unlike 1367, it often occurs in non-strict mode when values are truncated. Enabling STRICT mode promotes it to 1367, so fixes overlap.

Common Causes

Malformed Date or Time Literal

A date like '2024-13-01' or a time '25:00:00' exceeds valid ranges, leading to error 1367.

Numeric Overflow

Attempting to store 100000 into a TINYINT column exceeds its signed range of -128 to 127.

Undefined ENUM or SET Member

Inserting 'purple' into an ENUM('red','green','blue') column fails because 'purple' is not an allowed value.

Invalid Temporal Fraction

A DATETIME(3) column rejects a value with six microsecond digits unless precision matches.

Related Errors

Error 1292: Truncated Incorrect Value

Occurs in non-strict mode when MySQL silently truncates invalid input.

Error 1366: Incorrect String Value

Raised when character sets reject the supplied bytes.

Error 1264: Out of Range Value for Column

Similar to 1367 but focuses on numeric range overflow.

FAQs

Does this error only happen in strict SQL mode?

Error 1367 can appear in both strict and non-strict modes, but strict mode surfaces additional cases that would otherwise be truncated.

Can I force MySQL to coerce the value automatically?

You can disable strict mode, but this risks silent data loss. It is safer to validate and correct data or expand column types.

Why does the error mention '%s' twice?

The first %s is the data type MySQL expected; the second %s shows the actual invalid value encountered.

How does Galaxy help avoid this error?

Galaxy's SQL editor validates literals with AI copilot suggestions and highlights mismatched data types before you run the query, reducing runtime errors.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo