From: Ireneusz Pluta <ipluta@wp.pl>
To: Lee Hachadoorian <lee.hachadoorian@gmail.com>
Cc: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: Average of Array?
Date: Fri, 25 Jun 2010 21:33:55 +0200
Message-ID: <4C2504A3.4090502@wp.pl> (raw)
In-Reply-To: <AANLkTimbLPhLW7DzeTugvwClKBX-UQhOrUlR8afHydGB@mail.gmail.com>
References: <AANLkTimbLPhLW7DzeTugvwClKBX-UQhOrUlR8afHydGB@mail.gmail.com>
Lee Hachadoorian pisze:
> 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.
>
> Thanks,
>
>
Use unnest() ->
http://www.postgresql.org/docs/8.4/interactive/functions-array.html
# select avg(unnest) from (select unnest(ARRAY[1,2,null,3])) a;
avg
--------------------
2.0000000000000000
(1 row)
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: ipluta@wp.pl, lee.hachadoorian@gmail.com
Subject: Re: Average of Array?
In-Reply-To: <4C2504A3.4090502@wp.pl>
* 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