pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Glaesemann <grzm@seespotcode.net>
To: Dave Crooke <dcrooke@gmail.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: Picking out the most recent row using a time stamp column
Date: Thu, 24 Feb 2011 15:21:49 -0500
Message-ID: <08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net> (raw)
In-Reply-To: <AANLkTinTgU-jfPOhrfteBvhAhgG_8zknpk13N9L4QMap@mail.gmail.com>
References: <AANLkTinTgU-jfPOhrfteBvhAhgG_8zknpk13N9L4QMap@mail.gmail.com>


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






view thread (20+ messages)  latest in thread

Message-ID: <08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net>
Permalink:  ../08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net/
Also on:    postgresql.org/message-id/08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: grzm@seespotcode.net, dcrooke@gmail.com
  Subject: Re: Picking out the most recent row using a time stamp column
  In-Reply-To: <08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net>

* 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