Common SQL Errors

MySQL Error 1487 ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR - How to Fix Expression in RANGE/LIST VALUES must be constant

Galaxy Team
August 7, 2025

<p>The error appears when a RANGE or LIST partition definition includes a non-constant expression.</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 1487 ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR?

<p>MySQL Error 1487 ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR signals that RANGE or LIST partition values are not literal constants. Replace functions, columns, or variables with fixed literals or switch to HASH partitioning to resolve the issue quickly.</p>

Error Highlights

Typical Error Message

Expression in RANGE/LIST VALUES must be constant

Error Type

Syntax Error

Language

MySQL

Symbol

ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR

Error Code

1487

SQL State

HY000

Explanation

Table of Contents

What is MySQL Error 1487 ER_NO_CONST_EXPR_IN_RANGE_OR_LIST_ERROR?

MySQL raises this error while parsing a CREATE TABLE or ALTER TABLE statement that defines RANGE or LIST partitions. The engine expects every value supplied in the VALUES clause to be a literal constant.

When MySQL detects a column reference, function call, user variable, or any non-constant expression inside that clause, it aborts with SQLSTATE HY000 and error number 1487.

Why does MySQL require constant values?

Partition metadata must be deterministic at create time so that the optimizer can map rows to partitions without executing run-time calculations. Constant literals guarantee that mapping stays valid even after data changes.

What Causes This Error?

Using built-in functions such as YEAR, UPPER, NOW, or arithmetic inside VALUES clauses is the most frequent trigger.

Referencing table columns or session variables in partition definitions also breaks the constant requirement.

Dynamic SQL generators that template partition names sometimes introduce expressions accidentally, leading to this error on deployment.

How to Fix MySQL Error 1487

Rewrite every value list so that only literal constants remain. Replace UPPER('us') with 'US' or YEAR('2024-01-01') with 2024.

If deterministic mapping is impossible with constants, convert the table to HASH or KEY partitioning, which permits expressions in the partitioning column definition instead.

Common Scenarios and Solutions

Problem: LIST partition with function calls. Solution: Evaluate functions ahead of time and hard-code results.

Problem: RANGE partition on DATE using YEAR(date_col). Solution: Add a generated column storing YEAR(date_col) and partition by that column with constant limits.

Best Practices to Avoid This Error

Validate partition DDL in a staging database before production rollout to catch non-constant expressions early.

Automate DDL generation scripts to pre-compute literals rather than embedding functions.

Use Galaxy SQL editor linting to highlight non-constant expressions in partition definitions during code review.

Related Errors and Solutions

Error 1493 partition constant out of range appears when constants themselves violate the column range; fix by adjusting boundary values.

Error 1503 duplicates a partition name; ensure unique names across partitions.

Common Causes

Function Calls in VALUES

Using YEAR, MONTH, UPPER, or other functions produces a non-constant expression that MySQL cannot store as static metadata.

Column References

Including a table column directly inside VALUES violates the requirement for constants because column values differ per row.

User or System Variables

Session variables such as @country_code or system variables like @@lc_time_names are evaluated at run time, not creation time.

Related Errors

MySQL Error 1493 partition_const_domain_error

Raised when constant boundary values fall outside the column domain.

MySQL Error 1503 ER_DUP_PARTITION_NAME

Occurs when two partitions share the same identifier.

MySQL Error 1739 ER_PARTITION_FUNCTION_IS_NOT_ALLOWED

Triggers when partitioning function uses unsupported constructs.

FAQs

Can I use functions in HASH partitioning?

Yes. HASH and KEY partitioning allow expressions because mapping occurs at run time, unlike RANGE or LIST.

Does MySQL version matter for this error?

The constant requirement applies to all supported MySQL versions, including 5.7, 8.0, and later.

How does Galaxy help avoid Error 1487?

Galaxy highlights non-constant expressions in partition DDL during editing and suggests constant replacements via its AI copilot.

Will disabling partitioning remove the error?

Yes, dropping partitions or switching to a non-partitioned table eliminates the constant expression requirement altogether.

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