I have an Angular app which displays a list and a Scala API which provides data. I encountered a problem (and the languages don’t matter, is just about logic).
The problem is that the table from which I get data doesn’t have a primary key. Because I need to display the data plain in a widget (of type table) without sorts, just like in the database, I just do “SELECT * FROM table LIMIT 30
“.
The problem is when I want to change the page, my query became SELECT * FROM table OFFSET 30 LIMIT 30
ERROR: OFFSET can not be used without an ORDER BY option.
How can be solved this problem?
Advertisement
Answer
As the error says, you have to have an order by
clause in order to use the offset
clause. If you don’t have any meaningful way of sorting the table, you could just pick some arbitrary value, like the first column:
SELECT * FROM sometable ORDER BY column1 OFFSET 30 LIMIT 30