Hello. I am trying to get a pipelined query automated based on an index that has 4 columns. The last column is deterministic. All the other 3 columns can potentially have nulls as the value. For this example let's say it is ASC order. How can I build a where clause that take into account the potential nulls? When there are just two columns in the index as in Markus' fine example under Fetching the Next Page, it is not an issue because there is only the first (principal) column and the deterministic column. With more columns, there is always the possibility that one of the other columns (in this example columns 2 or 3) will have a true value in a record, but a null in the next sorted record. This can happen it the previous column jumps in value, starting the other columns over to the lowest value. However, if this happens it needs to know to look for the null. Because of this, my attempts so far seems to skip or jump to the wrong place when trying to get a sequential order. Hope that is clear. If not, please let me know. Thanks, Rocky
I was asked to add sample data and further explanation of my issue. Here is the index and a few records ordered by this index:
As you can see, when paginating to the first example record, it is pretty straight forward. However, to get to the next record in this order, the ordered column is no longer NULL, but the id_service is. So, the WHERE clause has to be able to look for a lower value in id_service (NULL are first) even though the order is ascending. In the example above, NULL values are used, but it would be the same using any lower value I guess. Sorry for the delay in updating my original post. Thanks, Rocky asked Oct 14 '14 at 20:53 Rocky |
We haven't implemented this yet in jOOQ, but we will soon (#2786). With jOOQ, you can write a SQL statement like this one:
Where
Depending on your combination of And if
I think you get the idea... answered Oct 15 '14 at 15:40 Lukas Eder |
Could you add some sample data and definitions?