Aggregate functions over arrays
I have a table like this: +-----+----------------+ | ID | array300 | +-----+----------------+ | 100 | {110,25,53,..} | | 101 | {56,75,59,...} | | 102 | {65,93,82,...} | | 103 | {75,70,80,...} | +-----+----------------+ array300 column is an array of 300 elements. I need to have arrays of 100 elements with every element representing the average of 3 elements of array300 . For this example the answer will be like: array100 {62.66,...} {63.33,...} {80,...} {78.33,...} Try something like this: SELECT id, unnest(array300) as val, ntile(100) OVER (PARTITION BY id) as bucket_num FROM your_table This