Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A8DE2476900 for ; Mon, 6 Jan 2003 11:37:01 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id BCDDD4768F5 for ; Mon, 6 Jan 2003 11:36:59 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id h06Gax0U014759; Mon, 6 Jan 2003 11:36:59 -0500 (EST) To: Tomasz Myrta Cc: Richard Huxton , pgsql-sql@postgresql.org Subject: Re: order by and aggregate In-reply-to: <3E198E18.5090408@klaster.net> References: <3E197A39.8070808@klaster.net> <200301061341.32945.dev@archonet.com> <3E198E18.5090408@klaster.net> Comments: In-reply-to Tomasz Myrta message dated "Mon, 06 Jan 2003 15:09:28 +0100" Date: Mon, 06 Jan 2003 11:36:58 -0500 Message-ID: <14758.1041871018@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/41 X-Sequence-Number: 10906 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