Re: Picking out the most recent row using a time stamp column

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Dave Crooke <dcrooke(at)gmail(dot)com>
Cc: pgsql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Picking out the most recent row using a time stamp column
Date: 2011-02-24 20:21:49
Message-ID: 08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On Feb 24, 2011, at 14:55, Dave Crooke wrote:

> Is there a more elegant way to write this, perhaps using PG-specific
> extensions?

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;

Michael Glaesemann
grzm seespotcode net

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Kevin Grittner 2011-02-24 20:24:15 Re: Picking out the most recent row using a time stamp column
Previous Message Kevin Grittner 2011-02-24 20:18:55 Re: Picking out the most recent row using a time stamp column