How to use aggregate functions on each array in a table, in Postgres? Imagine I have a table like:
games (
    scores INTEGER[]
)

And it had values
{1,2}
{3,4}
{}

I'd like to do arbitrary aggregations on that array.
For example, how would I do SELECT SUM(scores) AS total FROM games? Or an average? Or a max?
I'd like to get out:
3
7 
0

I tried SELECT SUM(UNNEST(scores)) AS total FROM games but that gave ERROR:  aggregate function calls cannot contain set-returning function calls.
You need a scalar subquery:
select (select sum(i)
        from unnest(scores) as x(i)) as total
from games;