proposal for a CookBook in postgresql.org
| От | Gerardo Herzig |
|---|---|
| Тема | proposal for a CookBook in postgresql.org |
| Дата | |
| Msg-id | 4A1154A5.80608@fmed.uba.ar обсуждение исходный текст |
| Ответы |
Re: proposal for a CookBook in postgresql.org
|
| Список | 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
В списке pgsql-sql по дате отправления: