Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alter table add partition error when sql_mode is set to ANSI_QUOTES #24980

Closed
tiancaiamao opened this issue May 31, 2021 · 4 comments
Closed
Labels
component/expression component/tablepartition This issue is related to Table Partition of TiDB. priority/P2 The issue has P2 priority. severity/minor type/bug The issue is confirmed as a bug.

Comments

@tiancaiamao
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

Originally reported from https://asktug.com/t/topic/69811

1. Minimal reproduce step (Required)

mysql> create TABLE TBL_KFK_VEHICLE_TEST (
    -> SourceId varchar(64) DEFAULT NULL,
    -> DeviceId varchar(64) DEFAULT NULL,
    -> PassTime timestamp NULL DEFAULT NULL,
    -> channelId varchar(64) DEFAULT NULL,
    -> address varchar(255) DEFAULT NULL,
    -> KEY DeviceId (DeviceId)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
    -> PARTITION BY RANGE (unix_timestamp(passtime))(
    -> PARTITION p20210429 VALUES LESS THAN ( UNIX_TIMESTAMP('2021-04-30 00:00:00') ),
    -> PARTITION p20210430 VALUES LESS THAN ( UNIX_TIMESTAMP('2021-05-01 00:00:00') ),
    -> PARTITION p20210501 VALUES LESS THAN ( UNIX_TIMESTAMP('2021-05-02 00:00:00') )
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> set @@sql_mode='ANSI_QUOTES';
Query OK, 0 rows affected (0.00 sec)

mysql>    ALTER TABLE TBL_KFK_VEHICLE_TEST ADD PARTITION (PARTITION p20210422 VALUES LESS THAN ( UNIX_TIMESTAMP('2021-06-23 00:00:00') ));
ERROR 1054 (42S22): Unknown column '2021-06-23 00:00:00' in 'expression'

2. What did you expect to see? (Required)

No error.

3. What did you see instead (Required)

The error message is misleading... what the hell is it actually?


When ANSI_QUOTES is set, UNIX_TIMESTAMP('2021-05-02 00:00:00’) is internally translated to

SELECT UNIX_TIMESTAMP("2021-05-02 00:00:00") 

And when the session reuse the parser to parse the SQL, it's translated to:

SELECT UNIX_TIMESTAMP(`2021-05-02 00:00:00`)

And anything inside ``` is recognized as column name.

4. What is your TiDB version? (Required)

master, 5.x

@tiancaiamao tiancaiamao added type/bug The issue is confirmed as a bug. component/expression priority/P2 The issue has P2 priority. severity/minor labels May 31, 2021
@tiancaiamao
Copy link
Contributor Author

PTAL @mjonss @qw4990

@mjonss
Copy link
Contributor

mjonss commented Feb 14, 2022

/component tablepartition

@ti-chi-bot ti-chi-bot added the component/tablepartition This issue is related to Table Partition of TiDB. label Feb 14, 2022
@djshow832
Copy link
Contributor

This is duplicated with #35281

@djshow832
Copy link
Contributor

closed by #35379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression component/tablepartition This issue is related to Table Partition of TiDB. priority/P2 The issue has P2 priority. severity/minor type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

4 participants