Seems the problem was with the custom aggregate function not being able to handle thousands of rows.
Соглашаюсь с условиями обработки персональных данных