pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Josh Berkus <josh@agliodbs.com>
Cc: Allan Engelhardt <allane@cybaea.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: MEDIAN as custom aggregate?
Date: Sat, 13 Oct 2001 01:31:54 -0400
Message-ID: <8803.1002951114@sss.pgh.pa.us> (raw)
In-Reply-To: <web-147007@davinci.ethosmedia.com>
References: <web-147007@davinci.ethosmedia.com>

"Josh Berkus" <josh@agliodbs.com> writes:
> The query I'll use is this:

> SELECT site, COUNT(pageviews) as count_views, AVG(pageviews) AS
> mean_views, median_views
> FROM sites, 
> 	(SELECT pageviews as median_view
> 	 FROM pageviews
> 	 LIMIT 1 OFFSET middlerec('pageviews')) med
> GROUP BY site, median_views;

> Where middlerec is a custom function that counts the records and returns
> the middle one.

Um ... does that work?  I thought LIMIT was fairly restrictive about
what it would take as a parameter --- like, constants or $n parameters
only.

I do not know of any median-finding algorithm that doesn't require a
depressingly large amount of storage...

			regards, tom lane



view thread (6+ messages)  latest in thread

Message-ID: <8803.1002951114@sss.pgh.pa.us>
Permalink:  ../8803.1002951114@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/8803.1002951114@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, josh@agliodbs.com, allane@cybaea.com
  Subject: Re: MEDIAN as custom aggregate?
  In-Reply-To: <8803.1002951114@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