I want to paginate through 2 different sources. I think I can do this using the thing where u join 2 queries into one, however, I don't want to merge them in parallel.
Is it possible to select the size of the first query, so I can limit the size of the second query; allowing me to properly paginate; first through the first query; and if partial / no result; then paginate through the second query.
I could obviously implement this at my application level, but I would prefer a single query.
After thinking about it, I could maybe do something like this?
with a as (... offset :offset limit :limit),
a_count as (select count(*) from a)
select * a
union
select ...
offset (select count from a_count)
limit greatest(:limit - (select count from a_count), 0)
Is this efficient? What can I improve?