Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.
like image 295
Nilay Singh Avatar asked Jul 31 '15 19:07

Nilay Singh


1 Answers

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

like image 137
Glorfindel Avatar answered Sep 20 '22 14:09

Glorfindel