Re: Average of Array?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Lee Hachadoorian <lee(dot)hachadoorian(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Average of Array?
Date: 2010-06-25 16:29:00
Message-ID: 5109.1277483340@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Lee Hachadoorian <lee(dot)hachadoorian(at)gmail(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Pavel Stehule 2010-06-25 16:29:10 Re: Average of Array?
Previous Message Lee Hachadoorian 2010-06-25 16:21:01 Average of Array?