Re: complicated running aggregate - Mailing list pgsql-general

From Greg Smith
Subject Re: complicated running aggregate
Date
Msg-id 4C236A59.1050504@2ndquadrant.com
Whole thread Raw
In response to complicated running aggregate  (Sim Zacks <sim@compulab.co.il>)
Responses Re: complicated running aggregate  (Sim Zacks <sim@compulab.co.il>)
List pgsql-general
Sim Zacks wrote:
> I am trying to build a query with a running total, but it is a bit
> complicated...Currently I'm generating this information using a plpsql loop, but I
> would like to change it to an SQL query, if possible.
>

It's hard to do a running total with the sort of requirements you have
using simple SQL.  If you have PostgreSQL 8.4, it's much much easier to
do that using the SQL Window functions:
http://www.postgresql.org/docs/current/static/tutorial-window.html

If you're on an earlier version, using a loop in a function is not a bad
approach.  Getting the query right without windowing is possible, but
painful enough that it may not be worth your trouble.

--
Greg Smith  2ndQuadrant US  Baltimore, MD
PostgreSQL Training, Services and Support
greg@2ndQuadrant.com   www.2ndQuadrant.us


pgsql-general by date:

Previous
From: Grzegorz Jaśkiewicz
Date:
Subject: Re: unexpected effect of FOREIGN KEY ON CASCADE DELETE
Next
From: Adrian Klaver
Date:
Subject: Re: unexpected effect of FOREIGN KEY ON CASCADE DELETE