Re: Best way to get the latest revision from a table

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Nikolas Everett" <nik9000(at)gmail(dot)com>
Cc: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Best way to get the latest revision from a table
Date: 2011-01-14 22:57:11
Message-ID: 4D308067020000250003962D@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Nikolas Everett <nik9000(at)gmail(dot)com> wrote:

> I'm really going to be doing this with an arbitrary list of As.

OK, how about this?:

CREATE TEMPORARY TABLE request (a INTEGER NOT NULL);
INSERT INTO request SELECT a FROM generate_series(2, 200) AS t(a);
ANALYZE request;
SELECT y.*
from (select a, max(revision) as revision
from test join request using (a)
group by a) x
join test y using (a, revision);
DROP TABLE request;

-Kevin

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Shaun Thomas 2011-01-14 23:06:48 Re: Best way to get the latest revision from a table
Previous Message Marti Raudsepp 2011-01-14 22:42:43 Re: "COPY TO stdout" statements occurrence in log files