From: Tom Lane <tgl@sss.pgh.pa.us>
To: Lee Hachadoorian <lee.hachadoorian@gmail.com>
Cc: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: Average of Array?
Date: Fri, 25 Jun 2010 12:29:00 -0400
Message-ID: <5109.1277483340@sss.pgh.pa.us> (raw)
In-Reply-To: <AANLkTimbLPhLW7DzeTugvwClKBX-UQhOrUlR8afHydGB@mail.gmail.com>
References: <AANLkTimbLPhLW7DzeTugvwClKBX-UQhOrUlR8afHydGB@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, lee.hachadoorian@gmail.com
Subject: Re: Average of Array?
In-Reply-To: <5109.1277483340@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox