Re: Average of Array? - Mailing list pgsql-sql

From Tom Lane
Subject Re: Average of Array?
Date
Msg-id 5109.1277483340@sss.pgh.pa.us
Whole thread Raw
In response to Average of Array?  (Lee Hachadoorian <lee.hachadoorian@gmail.com>)
List pgsql-sql
Lee Hachadoorian <lee.hachadoorian@gmail.com> writes:
> Is there a function that returns the average of the elements of an
> array? I'm thinking of something that would work like the avg()
> aggregate function where it returns the average of all non-NULL
> values. Can't find anything like it in the docs, and I'd like to make
> sure I'm not missing something.

You could unnest() the array and then apply the aggregate to the result.
unnest() is only built in in 8.4 and later, but it's not terribly hard
to write your own in previous versions.
        regards, tom lane


pgsql-sql by date:

Previous
From: Lee Hachadoorian
Date:
Subject: Average of Array?
Next
From: Pavel Stehule
Date:
Subject: Re: Average of Array?