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

From Ireneusz Pluta
Subject Re: Average of Array?
Date
Msg-id 4C2504A3.4090502@wp.pl
Whole thread Raw
In response to Average of Array?  (Lee Hachadoorian <lee.hachadoorian@gmail.com>)
List pgsql-sql
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)


pgsql-sql by date:

Previous
From: Tim Landscheidt
Date:
Subject: Re: enforcing constraints across multiple tables
Next
From: Frank Bax
Date:
Subject: How do I remove selected words from text field?