From: | Gerardo Herzig <gherzig(at)fmed(dot)uba(dot)ar> |
---|---|
To: | postgres list <pgsql-sql(at)postgresql(dot)org> |
Subject: | proposal for a CookBook in postgresql.org |
Date: | 2009-05-18 12:29:25 |
Message-ID: | 4A1154A5.80608@fmed.uba.ar |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-docs pgsql-sql |
I just saw a beatifull answer from Pavel, as an answer to this question:
"""
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
"""
With this function:
"""
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)
"""
I think this is a good time to propose some kind of CookBook, to
preserve this kind of answers.
Gerardo
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2009-05-18 12:34:51 | Re: proposal for a CookBook in postgresql.org |
Previous Message | Dave Page | 2009-05-18 11:57:32 | Re: proposal for a CookBook in postgresql.org |
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2009-05-18 12:34:51 | Re: proposal for a CookBook in postgresql.org |
Previous Message | Harald Fuchs | 2009-05-18 12:16:35 | Re: Extracting data from arrays |