From: | Dani Castaños <dcastanos(at)androme(dot)es> |
---|---|
To: | "'Pavel Stehule'" <pavel(dot)stehule(at)gmail(dot)com> |
Cc: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Extracting data from arrays |
Date: | 2009-05-18 13:25:44 |
Message-ID: | 005f01c9d7bc$271179d0$75346d70$@es |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Thank you very much!
-----Mensaje original-----
De: Pavel Stehule [mailto:pavel(dot)stehule(at)gmail(dot)com]
postgres=# 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=# select sum_items(array[1,2,3,4]); sum_items
-----------
10
(1 row)
regards
Pavel Stehule
2009/5/18 Dani Castaños <dcastanos(at)androme(dot)es>:
> Hi all,
>
> I've this query including arrays:
>
> SELECT hour[1:5], statistics_date
> FROM statistics_daily
> WHERE statistics_date = 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ños Sánchez
> dcastanos(at)androme(dot)es
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
From | Date | Subject | |
---|---|---|---|
Next Message | Pawel Socha | 2009-05-18 13:31:57 | Re: SUM Array values query |
Previous Message | Gerardo Herzig | 2009-05-18 13:04:58 | Re: proposal for a CookBook in postgresql.org |