pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <e99re41@DoCS.UU.SE>
To: Julian Scarfe <jscarfe@callnetuk.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgreSQL.org
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] DISTINCT ON: speak now or forever hold your peace
Date: Tue, 25 Jan 2000 11:59:04 +0100 (MET)
Message-ID: <Pine.GSO.4.02A.10001251157120.11899-100000@Val.DoCS.UU.SE> (raw)
In-Reply-To: <388D5F2C.DBD639D@callnetuk.com>

On Tue, 25 Jan 2000, Julian Scarfe wrote:

> Tom Lane wrote:
> > 
> > If I don't hear loud hollers very soon, I'm going to eliminate the
> > DISTINCT ON "feature" for 7.0.  As previously discussed, this feature
> > is not standard SQL and has no clear semantic interpretation.
> 
> I use 'distinct on' to get the most recent reports for each of a group of
> locations.  E.g.:
> 
> create table reports (
> location     varchar(16),
> report_time  datetime,
> report_text  text);
> 
> select distinct on location * from reports where location ~~ 'Lond%' order by
> location, reporttime desc;
> 
> to get the tuples that offer the most recent reports for each of London,
> Londonderry, Londy etc.
> 
> Is there an alternative?

select location, max(report_time) from reports group by location

This also has the negligible advantage that it gives you determinate
results.

-- 
Peter Eisentraut                  Sernanders vaeg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden




view thread (36+ messages)  latest in thread

Message-ID: <Pine.GSO.4.02A.10001251157120.11899-100000@Val.DoCS.UU.SE>
Permalink:  ../Pine.GSO.4.02A.10001251157120.11899-100000@Val.DoCS.UU.SE/
Also on:    postgresql.org/message-id/Pine.GSO.4.02A.10001251157120.11899-100000@Val.DoCS.UU.SE

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: e99re41@DoCS.UU.SE, jscarfe@callnetuk.com, tgl@sss.pgh.pa.us, pgsql-hackers@postgreSQL.org
  Subject: Re: [SQL] DISTINCT ON: speak now or forever hold your peace
  In-Reply-To: <Pine.GSO.4.02A.10001251157120.11899-100000@Val.DoCS.UU.SE>
  References: <388D5F2C.DBD639D@callnetuk.com> <Pine.GSO.4.02A.10001251157120.11899-100000@Val.DoCS.UU.SE>

* 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