select distinct on (a,ÂÂÂ b,ÂÂÂ c)
a,ÂÂ b c,ÂÂ time_stamp,ÂÂÂ value
from data
order by a, b, c, time_stamp desc;
The output produced is the same as this query:
select distinct on (a,ÂÂÂ b)
a,ÂÂ b,ÂÂ time_stamp,ÂÂÂ value
from data
order by a, b, time_stamp desc;
Not sure if this is considered a parser bug or not, but it feels slightly odd not to get an error.
PG 8.4.7 installed from Ubuntu 10.04's 64-bit build.
Cheers
Dave
On Thu, Feb 24, 2011 at 5:38 PM, Dave Crooke <dcrooke@xxxxxxxxx> wrote:
Thanks to all .... I had a tickling feeling at the back of my mind that there was a neater answer here. For the record, times (all from in-memory cached data, averaged over a bunch of runs):
Dependent subquery = 117.9 seconds
Join to temp table = 2.7 sec
DISTINCT ON = 2.7 sec
So the DISTINCT ON may not be quicker, but it sure is tidier.
Cheers
DaveOn Thu, Feb 24, 2011 at 2:24 PM, Kevin Grittner <Kevin.Grittner@xxxxxxxxxxxx> wrote:
Michael Glaesemann <grzm@xxxxxxxxxxxxxxx> wrote:Dang! ÂI forgot the DESC in my post! ÂThanks for showing the
> SELECT DISTINCT ON (data.id_key)
> Â Â Â Âdata.id_key, data.time_stamp, data.value
> Â FROM data
> Â ORDER BY data.id_key, data.time_stamp DESC;
*correct* version.
-Kevin