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 4D3088E70200002500039632@gw.wicourts.gov
Whole thread Raw
In response to Re: Best way to get the latest revision from a table  (Shaun Thomas <sthomas@peak6.com>)
Responses Re: Best way to get the latest revision from a table
List pgsql-performance
Shaun Thomas <sthomas@peak6.com> wrote:

> This actually looks like a perfect candidate for DISTINCT ON.
>
> SELECT DISTINCT ON (a, b) a, b, revision
>    FROM test
>   ORDER BY a, b DESC;

I wouldn't say perfect.  It runs about eight times slower than what
I suggested and returns a fairly random value for revision instead
of the max(revision).

-Kevin

pgsql-performance by date:

Previous
From: Shaun Thomas
Date:
Subject: Re: Best way to get the latest revision from a table
Next
From: Tom Lane
Date:
Subject: Re: Best way to get the latest revision from a table