Você pode agregar números fixos de linhas usando
row_number()
e aritmética:select min(date),
(array_agg(bid order by seqnum asc))[1] as open,
(array_agg(bid order by seqnum desc))[1] as close,
min(bid) as min_bid, max(bid) as max_bid
from (select t.*, row_number() over (order by date) as seqnum
from ticks t
) t
group by floor((seqnum - 1) / 500);
Isso usa "hack" para obter o
open
e close
-- usando matrizes.