Re: Sum() rows

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: lucas(at)presserv(dot)org
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Sum() rows
Date: 2005-06-01 17:00:32
Message-ID: 20050601170032.GB20923@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jun 01, 2005 at 08:49:00 -0300,
lucas(at)presserv(dot)org wrote:
> Yes,
> I tried it. In this table the query works fine, but in a big table
> (with aprox.
> 200.000 records) the query performace is very bad.
> I tried it (in the example table):
> SELECT *,(select sum(value) from tb1 as tb1_2 where tb1_2.id<=tb1_1.id) as
> subtot from tb1 as tb1_1 order by id;
>
> In a small table it works fine, but in a bigger table it works very slow.

Not surprising, since this is probably O(n^2).

> What is the better way??? Is there a sum() function that works how I want???

Having the application do the running sum is probably the best way to do it.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Cordova Juillerat Jorge Alejandro 2005-06-01 17:28:45 unsubscribe
Previous Message Alain Reymond 2005-06-01 16:00:49 How do write a query...