1492
MariaDBERRORNotablePartitioningHIGH confidence
Constant, random, or timezone-dependent expressions not allowed in partition function
Production Risk
Low — DDL error; the table will not be created.
What this means
ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR (1492, SQLSTATE HY000) is raised when a partitioning function contains expressions that are constant, non-deterministic, or timezone-dependent.
Why it happens
- 1Using NOW(), RAND(), UUID(), or other non-deterministic functions in the partition expression
- 2Using timezone-dependent functions like CONVERT_TZ() in the partition function
How to reproduce
trigger — this will error
trigger — this will error
CREATE TABLE t (created DATETIME)
PARTITION BY RANGE(UNIX_TIMESTAMP(created)) (
PARTITION p0 VALUES LESS THAN (UNIX_TIMESTAMP('2020-01-01'))
-- UNIX_TIMESTAMP with a literal is timezone-dependent
);expected output
ERROR 1492 (HY000): Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed
Fix
Use deterministic expressions in partition functions
Use deterministic expressions in partition functions
-- Use YEAR() or TO_DAYS() instead: CREATE TABLE t (created DATE) PARTITION BY RANGE(YEAR(created)) ( PARTITION p0 VALUES LESS THAN (2020), PARTITION p1 VALUES LESS THAN MAXVALUE );
Why this works
Partition functions must be deterministic so MySQL can consistently route rows to partitions.
Sources
Official documentation ↗
MySQL 8.0 — 1492 ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev