Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add LIMIT clause in postgressql Query?

Tags:

postgresql

I want to add LIMIT clause in postgressql query but its give me error

SELECT complaint_id FROM complaint_details_v2 a where a.road_dept SIMILAR TO 'PWDBnR' order by a.server_time desc LIMIT 0, 10

Below is the error:

ERROR: LIMIT #,# syntax is not supported
SQL state: 42601
Hint: Use separate LIMIT and OFFSET clauses.
Character: 87
like image 652
sumit kundan Avatar asked Oct 13 '25 05:10

sumit kundan


1 Answers

For the example above - skip the '0,' bit

SELECT complaint_id FROM complaint_details_v2 a where a.road_dept SIMILAR TO 
'PWDBnR' order by a.server_time desc LIMIT 10

LIMIT 0, 10 is not postgres dialect, use OFFSET. For example if you want to next 10 results:

SELECT complaint_id FROM complaint_details_v2 a where a.road_dept SIMILAR TO 
'PWDBnR' order by a.server_time desc OFFSET 10 LIMIT 10

http://www.sqlines.com/postgresql/limit_offset

like image 73
MrAleister Avatar answered Oct 15 '25 10:10

MrAleister