From: | Peter Eisentraut <e99re41(at)DoCS(dot)UU(dot)SE> |
---|---|
To: | Julian Scarfe <jscarfe(at)callnetuk(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgreSQL(dot)org, pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] DISTINCT ON: speak now or forever hold your peace |
Date: | 2000-01-25 10:59:04 |
Message-ID: | Pine.GSO.4.02A.10001251157120.11899-100000@Val.DoCS.UU.SE |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-sql |
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(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2000-01-25 11:01:22 | Re: [HACKERS] Well, then you keep your darn columns |
Previous Message | Peter Eisentraut | 2000-01-25 10:55:23 | Happy column adding (was RE: [HACKERS] Happy column dropping) |
From | Date | Subject | |
---|---|---|---|
Next Message | Palle Girgensohn | 2000-01-25 11:29:07 | Re: [SQL] Problem with large tuples. |
Previous Message | Peter Eisentraut | 2000-01-25 10:30:30 | Re: [SQL] Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace |