pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Lee Hachadoorian <lee.hachadoorian@gmail.com>
To: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: Average of Array?
Date: Fri, 25 Jun 2010 12:34:01 -0400
Message-ID: <AANLkTinW2Z7lBrPkMw9HIv7ZkGL-goMOSpBwRj2ToiIv@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimGlfovzQue7Gj8EHc3aA8gD3aIpKKoZ9amf16k@mail.gmail.com>
References: <AANLkTimbLPhLW7DzeTugvwClKBX-UQhOrUlR8afHydGB@mail.gmail.com>
	<AANLkTimGlfovzQue7Gj8EHc3aA8gD3aIpKKoZ9amf16k@mail.gmail.com>

Thanks Tom & Pavel, these are very helpful.

On Fri, Jun 25, 2010 at 12:29 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> Hello
>
> 2010/6/25 Lee Hachadoorian <lee.hachadoorian@gmail.com>:
>> 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.
>
> it doesn't exists, but it is simple to develop it
>
> CREATE OR REPLACE FUNCTION array_avg(double precision[])
> RETURNS double precision AS $$
> SELECT avg(v) FROM unnest($1) g(v)
> $$ LANGUAGE sql;
>
> Regards
>
> Pavel Stehule
>
>>
>> Thanks,
>>
>> --
>> Lee Hachadoorian
>> PhD Student, Geography
>> Program in Earth & Environmental Sciences
>> CUNY Graduate Center
>>
>> --
>> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-sql
>>
>



-- 
Lee Hachadoorian
PhD Student, Geography
Program in Earth & Environmental Sciences
CUNY Graduate Center



view thread (5+ messages)  latest in thread

Message-ID: <AANLkTinW2Z7lBrPkMw9HIv7ZkGL-goMOSpBwRj2ToiIv@mail.gmail.com>
Permalink:  ../AANLkTinW2Z7lBrPkMw9HIv7ZkGL-goMOSpBwRj2ToiIv@mail.gmail.com/
Also on:    postgresql.org/message-id/AANLkTinW2Z7lBrPkMw9HIv7ZkGL-goMOSpBwRj2ToiIv@mail.gmail.com

 · 

reply

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: lee.hachadoorian@gmail.com
  Subject: Re: Average of Array?
  In-Reply-To: <AANLkTinW2Z7lBrPkMw9HIv7ZkGL-goMOSpBwRj2ToiIv@mail.gmail.com>

* 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