Hi all,

here's a question related to XQuery, sorry for being slightly off-topic.

I'm struggling to find a way to combine the windowing clause and FLOWR in order to get a paged result of a subset of items which respect a given filter.

Of course I'm able to get this by first applying the filter to the whole input and then a second FLOWR for the windowing clause.

But I was wondering whether it's possible to streamline this into one single FLOWR.

Two bonus questions:

1. Will this actually be more efficient than the naive (two FLOWR)
   solution or is the almighty optimizer able to blend the two
   subsequent FLOWR on its own?
2. What if the input is unordered and I also would like to introduce
   sorting?

The closer I get is [1] which is not what I'd need because I get 2,4,6,8,10 as result for page 1 but I'd really want 10 results per page thus 2,4,6,8,10,12,14,16,18,20.

Thanks for any help on this in the meanwhile I'll stick to my naive solution.

Marco.

[1]

let $page := 1
let $count := 10
return
  for tumbling window $w in (1 to 100)
  start $first at $s when ($s = 1 + ($page - 1) * $count)
  end $last at $e when ($e - $s = $count - 1)
  return
    $w ! (if (. mod 2 = 0 ) then . else ())

Reply via email to