xxxxxxxxxx
select to_timestamp(floor((extract('epoch' from TIMESTAMP_COLUMN) / INTERVAL_SECONDS )) * INTERVAL_SECONDS) as interval
, count(1) result_count
, string_agg(cast(id as varchar), ',') as ids
from TABLE_NAME
group by interval
order by interval