Victor:
On Fri, Aug 19, 2016 at 8:01 PM, Victor Blomqvist <vb@viblo.se> wrote:
> Thanks! A sub select seems to do it.
I suspected it would be needed, that's why I sugested it.
I prefer to write the queries as CTEs because they are much easier to
read, but IIRC they are some kind of 'optimization fences'. Some times
I end up using psql macros to write queries in CTE-like order in my
scripts and compose them into sub selects when I have this problems.
> Checking these two queries I can see that the first one visits the
> max 50 rows its allowed to and returns 5 rows, while the second one
> finish off after 13 rows fetched and returns the full 10 rows.
Good. The only problem is you are not guaranteed a result, like in the
contrived example I gave, but if it is what you want this is a way to
go.
Francisco Olarte.