Re: order by and aggregate - Mailing list pgsql-sql

From Richard Huxton
Subject Re: order by and aggregate
Date
Msg-id 200301061341.32945.dev@archonet.com
Whole thread Raw
In response to order by and aggregate  (Tomasz Myrta <jasiek@klaster.net>)
List pgsql-sql
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
before processing. Could you show details of your function - there may be a
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.

--  Richard Huxton


pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Grant execute on functions; related objects permissions ?
Next
From: Tomasz Myrta
Date:
Subject: Re: order by and aggregate