How to convert a MySQL `LIMIT` clause to a PostgreSQL `LIMIT` clause?

时间:2015-07-31 19:49:24

标签: mysql postgresql

An example MySQL query:

    SELECT message_id, message_text
    FROM messages
    LIMIT 0 , 30

I am getting this hint as a error:

HINT: Use separate LIMIT and OFFSET clauses.

1 个答案:

答案 0 :(得分:12)

Compare the LIMIT syntax of MySQL:

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

to the one used by Postgres:

[LIMIT { number | ALL }] [OFFSET number]

This should give you enough information that you need to replace LIMIT 0, 30 with LIMIT 30 OFFSET 0. (Note that the latter is also valid MySQL syntax).