Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id F3E54476A08 for ; Mon, 6 Jan 2003 12:04:58 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 917404769FC for ; Mon, 6 Jan 2003 12:04:56 -0500 (EST) Received: from klaster.net (pc54.krakow.cvx.ppp.tpnet.pl [213.76.38.54]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 5F9D72B21C; Mon, 6 Jan 2003 18:03:28 +0100 (CET) Message-ID: <3E19B60A.9080701@klaster.net> Date: Mon, 06 Jan 2003 17:59:54 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.2b) Gecko/20021016 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Richard Huxton , pgsql-sql@postgresql.org Subject: Re: order by and aggregate References: <3E197A39.8070808@klaster.net> <200301061341.32945.dev@archonet.com> <3E198E18.5090408@klaster.net> <14758.1041871018@sss.pgh.pa.us> In-Reply-To: <3E197A39.8070808@klaster.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/42 X-Sequence-Number: 10907 Tom Lane wrote: > Tomasz Myrta writes: > > >Standard Postgresql aggregate functions don't need sorted data, but my > >function needs. Look at the data: > > > >3 3 > >-2 1 > >6 7 *** max_sum=7 > >-3 4 > >2 6 > > > But if the input data is sorted into increasing order, then the largest > running sum value is always at the end. Therefore max(sum()) is > equivalent to sum(); therefore you do not need the special aggregate, > nor the ordering. > > regards, tom lane Sorting data by "value" was only an example, In my case data is sorted by another key and has mixed positive and negative values. Tomasz Myrta