Re: order by and aggregate

From: Richard Huxton <dev(at)archonet(dot)com>
To: Tomasz Myrta <jasiek(at)klaster(dot)net>, pgsql-sql(at)postgresql(dot)org
Subject: Re: order by and aggregate
Date: 2003-01-06 13:41:32
Message-ID: 200301061341.32945.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2003-01-06 13:50:19 Re: Grant execute on functions; related objects permissions ?
Previous Message Tomasz Myrta 2003-01-06 12:44:41 order by and aggregate