0

I need to add a partition to an already partitioned table. My code adds a partition p190409 that would hold some data. The query is as follows:

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));

The same while working perfectly fine on a mysql client, yields the following error through code:

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

6
  • why are you try to do this in Java? Commented Apr 9, 2019 at 6:34
  • I've to write an API that would be scheduled to run everyday, to add a partition corresponding to that day Commented Apr 9, 2019 at 6:41
  • Many MySQL API's cannot execute more than one query in a call. Try splitting it into three queries. Commented Apr 9, 2019 at 6:42
  • @Nick, Makes sense, will try it out and update info here Commented Apr 9, 2019 at 6:48
  • 1
    @cricketeer it seems I should have posted it as an answer! :-) Commented Apr 9, 2019 at 8:56

1 Answer 1

1

Looks like the method you are using to execute the query only admit one at the time, so instead off executing all queries at once do it one by one:

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))");
Sign up to request clarification or add additional context in comments.

1 Comment

@JoopEggen thanks for your observations, I have correct them :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.