pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gerardo Herzig <gherzig@fmed.uba.ar>
To: postgres list <pgsql-sql@postgresql.org>
Subject: proposal for a CookBook in postgresql.org
Date: Mon, 18 May 2009 09:29:25 -0300
Message-ID: <4A1154A5.80608@fmed.uba.ar> (raw)

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



view thread (12+ messages)  latest in thread

Message-ID: <4A1154A5.80608@fmed.uba.ar>
Permalink:  ../4A1154A5.80608@fmed.uba.ar/
Also on:    postgresql.org/message-id/4A1154A5.80608@fmed.uba.ar

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gherzig@fmed.uba.ar
  Subject: Re: proposal for a CookBook in postgresql.org
  In-Reply-To: <4A1154A5.80608@fmed.uba.ar>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox