Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4B3254758E6 for ; Mon, 6 Jan 2003 07:41:04 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 98B454753A1 for ; Mon, 6 Jan 2003 07:41:03 -0500 (EST) Received: from klaster.net (pa39.krakow.cvx.ppp.tpnet.pl [213.76.36.39]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id A095E2B21C for ; Mon, 6 Jan 2003 13:39:35 +0100 (CET) Message-ID: <3E197A39.8070808@klaster.net> Date: Mon, 06 Jan 2003 13:44:41 +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: pgsql-sql@postgresql.org Subject: order by and aggregate Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/33 X-Sequence-Number: 10898 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. 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 I found I can obey this using subselect: select maxsum(X.value) from (select value from some_table order by some_field) X I can't create subselect, because I want to change this query into a view. In my case postgresql doesn't use indexes on subselect inside a view. What should I do? Regards, Tomasz Myrta