pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tomasz Myrta <jasiek@klaster.net>
Cc: Richard Huxton <dev@archonet.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: order by and aggregate
Date: Mon, 06 Jan 2003 11:36:58 -0500
Message-ID: <14758.1041871018@sss.pgh.pa.us> (raw)
In-Reply-To: <3E198E18.5090408@klaster.net>
References: <3E197A39.8070808@klaster.net>
	<200301061341.32945.dev@archonet.com>
	<3E198E18.5090408@klaster.net>

Tomasz Myrta <jasiek@klaster.net> writes:
> Standard Postgresql aggregate functions don't need sorted data, but my 
> function needs. Look at the data:
> <value>   <sum>
> 3	  3
> -2        1
> 6         7 *** max_sum=7
> -3        4
> 2         6

But if the input data is sorted into increasing order, then the largest
running sum value is always at the end.  Therefore max(sum()) is
equivalent to sum(); therefore you do not need the special aggregate,
nor the ordering.

			regards, tom lane



view thread (9+ messages)  latest in thread

Message-ID: <14758.1041871018@sss.pgh.pa.us>
Permalink:  ../14758.1041871018@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14758.1041871018@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, jasiek@klaster.net, dev@archonet.com
  Subject: Re: order by and aggregate
  In-Reply-To: <14758.1041871018@sss.pgh.pa.us>

* 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