order by and aggregate - Mailing list pgsql-sql

From Tomasz Myrta
Subject order by and aggregate
Date
Msg-id 3E197A39.8070808@klaster.net
Whole thread Raw
Responses Re: order by and aggregate  (Richard Huxton <dev@archonet.com>)
Re: order by and aggregate  (Tomasz Myrta <jasiek@klaster.net>)
Re: order by and aggregate  (Tomasz Myrta <jasiek@klaster.net>)
Re: order by and aggregate  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: order by and aggregate  (Tomasz Myrta <jasiek@klaster.net>)
Re: order by and aggregate  (Tomasz Myrta <jasiek@klaster.net>)
List pgsql-sql
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



pgsql-sql by date:

Previous
From: "Tambet Matiisen"
Date:
Subject: Re: Grant execute on functions; related objects permissions ?
Next
From: Bruno Wolff III
Date:
Subject: Re: Grant execute on functions; related objects permissions ?