Re: Best way to get the latest revision from a table - Mailing list pgsql-performance

From Kevin Grittner
Subject Re: Best way to get the latest revision from a table
Date
Msg-id 4D308067020000250003962D@gw.wicourts.gov
Whole thread Raw
In response to Re: Best way to get the latest revision from a table  (Nikolas Everett <nik9000@gmail.com>)
List pgsql-performance
Nikolas Everett <nik9000@gmail.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

pgsql-performance by date:

Previous
From: Marti Raudsepp
Date:
Subject: Re: "COPY TO stdout" statements occurrence in log files
Next
From: Shaun Thomas
Date:
Subject: Re: Best way to get the latest revision from a table