pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomasz Myrta <jasiek@klaster.net>
To: pgsql-sql@postgresql.org
Subject: order by and aggregate
Date: Mon, 06 Jan 2003 13:44:41 +0100
Message-ID: <3E197A39.8070808@klaster.net> (raw)

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




view thread (9+ messages)  latest in thread

Message-ID: <3E197A39.8070808@klaster.net>
Permalink:  ../3E197A39.8070808@klaster.net/
Also on:    postgresql.org/message-id/3E197A39.8070808@klaster.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jasiek@klaster.net
  Subject: Re: order by and aggregate
  In-Reply-To: <3E197A39.8070808@klaster.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox