Re: Count of records in a row

From: Robert James <srobertjames(at)gmail(dot)com>
To: Rémi Cura <remi(dot)cura(at)gmail(dot)com>
Cc: David Johnston <polobo(at)yahoo(dot)com>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Count of records in a row
Date: 2013-10-22 13:06:47
Message-ID: CAGYyBghy0HqXBHopgqkfrb1OUrw2eFG8y-yKy7RbW--+Axp4-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/22/13, Rémi Cura <remi(dot)cura(at)gmail(dot)com> wrote:
> But it is immensely easier and sometimes mandatory to use instead
> a plpgsql function using cursor (or cursors).
>
> It would be something like that in plpgsql :
>
> cursor on table of letter ordered
> accum = 0;
> loop on rows of table ordered
>
> if letter = previous letter, new_id = accum
> else accum ++ ; new_id = accum
>
> old letter = new_letter
> new letter = next letter;
>
> end of loop,

Shouldn't it be possible to do that with a FOR loop without a cursor?

It might be that procedural is the way to go. But I still believe
that relational algebra can handle this, even without a window
function. Something like:

SELECT event e, COUNT(
SELECT event oe ... WHERE oe.event_time > e.event_time AND NOT EXISTS (
SELECT event te WHERE te.event_time > e.event_time AND
te.event_time < oe.event_time))

.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rémi Cura 2013-10-22 13:16:19 Re: Count of records in a row
Previous Message Albe Laurenz 2013-10-22 11:22:47 Re: Why there are TRANS_START and TRANS_INPROGRESS