Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 71428632621 for ; Fri, 25 Jun 2010 16:34:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 73320-10 for ; Fri, 25 Jun 2010 19:33:58 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx3.wp.pl (mx3.wp.pl [212.77.101.7]) by mail.postgresql.org (Postfix) with ESMTP id BC9976321BE for ; Fri, 25 Jun 2010 16:33:58 -0300 (ADT) Received: (wp-smtpd smtp.wp.pl 24636 invoked from network); 25 Jun 2010 21:33:56 +0200 Received: from aaym246.neoplus.adsl.tpnet.pl (HELO [127.0.0.1]) (ipluta@[83.6.124.246]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with AES256-SHA encrypted SMTP for ; 25 Jun 2010 21:33:56 +0200 Message-ID: <4C2504A3.4090502@wp.pl> Date: Fri, 25 Jun 2010 21:33:55 +0200 From: Ireneusz Pluta User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Lee Hachadoorian CC: pgsql-sql Subject: Re: Average of Array? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A. X-WP-SPAM: NO 0000000 [ETPE] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.61 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/94 X-Sequence-Number: 34285 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)