在 mysql 客户端上执行且没有任何错误的 sql 查询在通过代码执行时失败并出现语法错误

A sql query that executes without any errors on mysql client fails with a syntax error when executed through code

我需要为已经分区的 table 添加一个分区。我的代码添加了一个分区 p190409 来保存一些数据。查询如下:

alter table db.table drop partition future;
alter table db.table add partition (partition p190409 values less than (to_days('2019-04-09 11:50:06')));
alter table db.table add partition (partition future values less than (MAXVALUE));

同样在 mysql 客户端上工作得很好,通过代码产生以下错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'alter table db.table add partition (partition p190409 values less' at line 1

看起来你用来执行查询的方法一次只接受一个,所以不要一次执行所有查询,而是一个一个地执行:

executeUpdate("alter table db.table drop partition future");
executeUpdate("alter table db.table add partition (partition p190409 values less than (to_days('2019-04-09 11:50:06')))");
executeUpdate("table db.table add partition (partition future values less than (MAXVALUE))");