Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6EFA5476060 for ; Mon, 6 Jan 2003 08:41:33 -0500 (EST) Received: from anchor-post-32.mail.demon.net (anchor-post-32.mail.demon.net [194.217.242.90]) by postgresql.org (Postfix) with ESMTP id E05E047605F for ; Mon, 6 Jan 2003 08:41:32 -0500 (EST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-32.mail.demon.net with esmtp (Exim 3.35 #1) id 18VXVT-00040F-0W; Mon, 06 Jan 2003 13:41:32 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id BCB4B17574; Mon, 6 Jan 2003 13:41:30 +0000 (GMT) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 028C01753E; Mon, 6 Jan 2003 13:41:29 +0000 (GMT) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: Tomasz Myrta , pgsql-sql@postgresql.org Subject: Re: order by and aggregate Date: Mon, 6 Jan 2003 13:41:32 +0000 User-Agent: KMail/1.4.3 References: <3E197A39.8070808@klaster.net> In-Reply-To: <3E197A39.8070808@klaster.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200301061341.32945.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/35 X-Sequence-Number: 10900 On Monday 06 Jan 2003 12:44 pm, Tomasz Myrta wrote: > Hi > I created my own aggregate function working as max(sum(value)) > It adds positive and negative values and finds maximum of this sum. > To work properly this function needs data to be sorted. I'm not sure that an aggregate function should require data to be sorted=20 before processing. Could you show details of your function - there may be a= =20 way to rewrite it to handle unsorted data. > select > maxsum(value) > from some_table > order by some_field > > doesn't work: > ERROR: Attribute some_table.some_field must be GROUPed or used in an > aggregate function The "order by" isn't necessarily handled before calculating maxsum() anyway. --=20 Richard Huxton