From: Shaun Thomas <sthomas@peak6.com>
To: Josh Berkus <josh@agliodbs.com>
Cc: Dave Crooke <dcrooke@gmail.com>
Cc: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: Michael Glaesemann <grzm@seespotcode.net>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Picking out the most recent row using a time stamp column
Date: Thu, 24 Feb 2011 18:58:33 -0600
Message-ID: <4D66FEB9.6000501@peak6.com> (raw)
In-Reply-To: <4D66F5B0.5080502@agliodbs.com>
References: <AANLkTinTgU-jfPOhrfteBvhAhgG_8zknpk13N9L4QMap@mail.gmail.com>
<08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net>
<4D666A0F020000250003AFCE@gw.wicourts.gov>
<AANLkTimSmjGrCqwZWRXU1_=FW0adbWdxLXMK0n=Vw+Cc@mail.gmail.com>
<4D66F5B0.5080502@agliodbs.com>
On 02/24/2011 06:20 PM, Josh Berkus wrote:
> SELECT id_key, time_stamp, value
> FROM (
> SELECT id_key, time_stamp, value,
> row_number()
> OVER ( PARTITION BY id_key
> ORDER BY time_stamp DESC)
> as ranking
> FROM thetable
> ) as filtered_table
> WHERE ranking = 1
Why did you use row_number instead of rank?
I am now curious how the speed compares though. I still think the
DISTINCT ON will be faster, but it would be a great surprise.
--
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas@peak6.com
______________________________________________
See http://www.peak6.com/email_disclaimer.php
for terms and conditions related to this email
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-performance@postgresql.org
Cc: sthomas@peak6.com, josh@agliodbs.com, dcrooke@gmail.com, Kevin.Grittner@wicourts.gov, grzm@seespotcode.net
Subject: Re: Picking out the most recent row using a time stamp column
In-Reply-To: <4D66FEB9.6000501@peak6.com>
* 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