This topic is locked
[SOLVED]

 Sorting with NULL values and back button

9/4/2013 8:52:40 AM
PHPRunner General questions
W
wpl author

Hi all,
I need some advice on sorting a table (PostgreSQL 8.x and 9.x) on a field containing NULL values. Among the ~9000 records in this table there are ~2500 records with NULL values in a field I would like to sort the table on. I do sorting on the "query" page of PHP Runner ("order by ..."). This works fine, ie the list page is sorted as expected. However, if I click the "View" oder "Edit" icon of a record on the list page of the generated app and then decide to return to the list with the "back" button, I will be sent to a totally different page than the one I started from. The page the app is redirecting to depends on the selected page size! If I started on page 1, I will be sent to page 126. If I click the view button of one of the records on page 126 and go back, I will be at page 251, and so on. There is a displacement of 125 pages when page size is set to 20. The displacement will be 50 when page size is 50 and will be 25 when page size is 100. So, how does PHP Runner determine to which page it should redirect to after the back button has been clicked? How does this relate to sorting? BTW, If I remove the sorting, everything works as expected.
Tia

Sergey Kornilov admin 9/4/2013

While I don't have the answer I believe this might be related to the fact sort field has NULL values. By default sorting by NULL leads to unpredictable results.
Here is the post that provides two suggestions (top two answers) that may fix this issue:

http://stackoverflow.com/questions/9510509/postgresql-sort-by-datetime-asc-null-first

W
wpl author 9/4/2013



While I don't have the answer I believe this might be related to the fact sort field has NULL values. By default sorting by NULL leads to unpredictable results.
Here is the post that provides two suggestions (top two answers) that may fix this issue:

http://stackoverflow.com/questions/9510509/postgresql-sort-by-datetime-asc-null-first


Sergey,
thanks. But I tried that already. In PostgreSQL, there is even an index option NULLS FIRST/LAST. But this does not solve the problem of the back button not redirecting to the correct page. So one would have to store the page number before going to the Edit/View page and return to the stored page when the back button is clicked. Is there any chance to implement something like this?
Thanks

W
wpl author 9/5/2013



While I don't have the answer I believe this might be related to the fact sort field has NULL values. By default sorting by NULL leads to unpredictable results.
Here is the post that provides two suggestions (top two answers) that may fix this issue:

http://stackoverflow.com/questions/9510509/postgresql-sort-by-datetime-asc-null-first



Sergey,
sorry. Seems like I didn't test carefully enough. The info from your link did the trick with "ORDER BY ... NULLS LAST"
Thanks