Skip site navigation (1) Skip section navigation (2)

Re: Average of Array?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
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 16:29:10
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql

2010/6/25 Lee Hachadoorian <lee(dot)hachadoorian(at)gmail(dot)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;


Pavel Stehule

> Thanks,
> --
> Lee Hachadoorian
> PhD Student, Geography
> Program in Earth & Environmental Sciences
> CUNY Graduate Center
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:

In response to


pgsql-sql by date

Next:From: Lee HachadoorianDate: 2010-06-25 16:34:01
Subject: Re: Average of Array?
Previous:From: Tom LaneDate: 2010-06-25 16:29:00
Subject: Re: Average of Array?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group