Home > Net >  Passing datetime column in partitioning still giving error
Passing datetime column in partitioning still giving error

Time:09-08

Getting error Although my column CreatedAt is datetime still im getting this error on partitioning the table

**Error Code: 1486. Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed**

default data

1,"2022-07-21 11:30:31","2022-08-31 11:16:46"
2,"2022-07-21 11:35:50","2022-08-31 11:16:46"

Table structure

CREATE TABLE `click` (
  `id` int(11) DEFAULT NULL,
  `CreatedAt` datetime DEFAULT NULL,
  `UpdatedAt` datetime
) ENGINE=InnoDB DEFAULT CHARSET=latin1



ALTER TABLE X.`click` PARTITION BY RANGE (UNIX_TIMESTAMP(CreatedAt))
PARTITIONS 4 (
PARTITION drop_old VALUES LESS THAN (UNIX_TIMESTAMP('2022-07-01')),
PARTITION p_20220801 VALUES LESS THAN (UNIX_TIMESTAMP('2022-08-01')),
PARTITION p_20220901 VALUES LESS THAN (UNIX_TIMESTAMP('2022-09-01')),
PARTITION future VALUES LESS THAN MAXVALUE);

CodePudding user response:

he manual has an example of how to use a timestamp in partitioning https://dev.mysql.com/doc/refman/8.0/en/partitioning-range.html for your example to work you need to change createdat datatype to timestamp.

  • Related