Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 7142A633D2E for ; Mon, 18 May 2009 10:25:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 74955-03 for ; Mon, 18 May 2009 10:25:42 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from fafnir.androme.com (fafnir.androme.com [62.58.96.158]) by mail.postgresql.org (Postfix) with ESMTP id 39FF4633B5A for ; Mon, 18 May 2009 10:25:49 -0300 (ADT) Received: by fafnir.androme.com (Postfix, from userid 1003) id 1D8EFB97ACD; Mon, 18 May 2009 15:25:47 +0200 (CEST) From: =?utf-8?Q?Dani_Casta=C3=B1os?= To: "'Pavel Stehule'" Cc: References: <003b01c9d7a5$b7b22190$271664b0$@es> <162867790905180410n670062b0ud2d7fdd0e6521a2@mail.gmail.com> In-Reply-To: <162867790905180410n670062b0ud2d7fdd0e6521a2@mail.gmail.com> Subject: Re: Extracting data from arrays Date: Mon, 18 May 2009 15:25:44 +0200 Message-ID: <005f01c9d7bc$271179d0$75346d70$@es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcnXqVFJsIgoeRxKTLiwuIKB7diZbQAErm+Q Content-Language: es X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200905/79 X-Sequence-Number: 32571 Thank you very much! -----Mensaje original----- De: Pavel Stehule [mailto:pavel.stehule@gmail.com]=20 postgres=3D# create or replace function sum_items(bigint[]) returns bigint as $$ select sum($1[i])::bigint from generate_series(array_lower($1,1), array_upper($1,1)) g(i)$$ language sql immutable; CREATE FUNCTION Time: 2,510 ms postgres=3D# select sum_items(array[1,2,3,4]); sum_items ----------- 10 (1 row) regards Pavel Stehule 2009/5/18 Dani Casta=C3=B1os : > Hi all, > > I've this query including arrays: > > SELECT hour[1:5], statistics_date > FROM statistics_daily > WHERE statistics_date =3D to_date( '03/01/2008', 'DD/MM/YYYY' ) > > Result: > > hour | statistics_date > ----------------------------+----------------- > {1800,1800,1800,1800,1800} | 2008-01-03 > > > I'm just wondering if there's some way to retrieve the hour column as = the > sum of the array values... Just like this: > > hour | statistics_date > ----------------------------+----------------- > 9000 | 2008-01-03 > > > Hour is a bigint[] array column. > My version of postreSQL is 8.1.9 > > Thank you in advanced! > > -- > Dani Casta=C3=B1os S=C3=A1nchez > dcastanos@androme.es > > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql >