Re: [SQL] order by and aggregate

2003-01-06 Thread Tomasz Myrta
Tom Lane wrote: I don't understand what you think is wrong with this solution. It works fine for me: regression=# create view vv as regression-# select max(unique1) from (select unique1 from tenk1 regression(# order by unique2) x; CREATE VIEW regression=# explain select * from vv;

Re: [SQL] order by and aggregate

2003-01-06 Thread Tomasz Myrta
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 >-21 >6 7 *** max_sum=7 >-34 >2 6 But if the input data is sorted into increasing order, then the largest ru

Re: [SQL] order by and aggregate

2003-01-06 Thread Tom Lane
Tomasz Myrta <[EMAIL PROTECTED]> writes: > Standard Postgresql aggregate functions don't need sorted data, but my > function needs. Look at the data: > > 3 3 > -21 > 6 7 *** max_sum=7 > -34 > 2 6 But if the input data is sorted into increasing order, then

Re: [SQL] order by and aggregate

2003-01-06 Thread Tom Lane
Tomasz Myrta <[EMAIL PROTECTED]> writes: > 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

Re: [SQL] order by and aggregate

2003-01-06 Thread Tomasz Myrta
[EMAIL PROTECTED] wrote: Ah - so it's maximum of a running-total rather than a sum. Sorry, my english still has a lot of black-holes :-( AFAIK you are out of luck with aggregate functions. The order data is supplied to them is *not* defined - the "order by" operates just before results are ou

Re: [SQL] order by and aggregate

2003-01-06 Thread dev
> Richard Huxton wrote: > >> 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. >> >> >>

Re: [SQL] order by and aggregate

2003-01-06 Thread Tomasz Myrta
Richard Huxton wrote: 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 aggre

Re: [SQL] order by and aggregate

2003-01-06 Thread Richard Huxton
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 r

[SQL] order by and aggregate

2003-01-06 Thread Tomasz Myrta
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.som