From: Bruno Wolff III <bruno@wolff.to>
To: lucas@presserv.org
Cc: pgsql-sql@postgresql.org
Subject: Re: Sum() rows
Date: Wed, 1 Jun 2005 12:00:32 -0500
Message-ID: <20050601170032.GB20923@wolff.to> (raw)
In-Reply-To: <20050601084900.duzlosra25wkwgsw@www.presserv.org>
References: <20050531133648.cypdc5lnjtc0wsws@www.presserv.org>
<20050531171708.GB5899@wolff.to>
<20050601084900.duzlosra25wkwgsw@www.presserv.org>
On Wed, Jun 01, 2005 at 08:49:00 -0300,
lucas@presserv.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.
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: bruno@wolff.to, lucas@presserv.org
Subject: Re: Sum() rows
In-Reply-To: <20050601170032.GB20923@wolff.to>
* 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