1

See below. If use like this:

select product_id, name from product limit (1-1)*5, 5; ERROR 1064 (42000): 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 '(1-1)*5, 5' at line 1

but if use like this:

select (1-1)*5 ; +---------+ | (1-1)*5 | +---------+ | 0 | +---------+ It's ok.

How to use math expression in first statement?

3
  • 2
    dev.mysql.com/doc/refman/5.5/en/select.html: LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants.” And it goes on to list two exceptions, placeholders in prepared statements, and parameters or variables in a stored procedure (the latter only from 5.5.6 on). So looks like other than that, you can use only integers there, and not expressions. Commented Jan 18, 2015 at 3:26
  • 1
    @CBroe put that in answer form so we can upvote. Commented Jan 18, 2015 at 3:28
  • Why would you need to do that in the first place? It looks like you are working on some pagination functionality, so why wouldn't you just calculate the page number in your application logic? Commented Jan 18, 2015 at 3:54

1 Answer 1

2

http://dev.mysql.com/doc/refman/5.5/en/select.html says,

LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants.

And it goes on to list two exceptions,

  • placeholders in prepared statements, and

  • parameters or variables in a stored procedure (the latter only from 5.5.6 on).

So looks like other than that, you can use only integers there, and not expressions.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It seems that if want to support this funtion, you have to modify mysql source code.

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.