Re: Average of Array?

From: Ireneusz Pluta <ipluta(at)wp(dot)pl>
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 19:33:55
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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() ->

# select avg(unnest) from (select unnest(ARRAY[1,2,null,3])) a;
(1 row)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Frank Bax 2010-06-25 22:23:48 How do I remove selected words from text field?
Previous Message Tim Landscheidt 2010-06-25 19:01:14 Re: enforcing constraints across multiple tables