Fastest way to get max tstamp - Mailing list pgsql-sql

From Henry Ortega
Subject Fastest way to get max tstamp
Date
Msg-id 2bffcc330608281110j404e3fd1q9d6d27a6a97ad31d@mail.gmail.com
Whole thread Raw
Responses Re: Fastest way to get max tstamp
List pgsql-sql
This is my table:<br /> name | program | effective  |           tstamp           | rate <br
/>------+---------+------------+----------------------------+------<br/> jdoe | AAA     | 2006-07-01 | 2006-07-16
23:42:13.809214|   20 <br /> jdoe | BBB     | 2006-07-01 | 2006-07-16 23:42:13.809214 |   20<br /> jdoe | AAA     |
2006-08-16| 2006-08-25 11:56:50.380575 |   20<br /> jdoe | BBB     | 2006-08-16 | 2006-08-25 11:56:50.380575 |   20<br
/> jdoe| AAA     | 2006-08-16 | 2006-08-25 11:57: 17.394854 |   20<br /> jdoe | BBB     | 2006-08-16 | 2006-08-25
11:57:17.394854|   20<br /> jdoe | AAA     | 2006-09-01 | 2006-08-28 12:38:42.486513 |   20<br /> jdoe | BBB     |
2006-09-01| 2006-08-28 12:38:42.486513 |   20<br /><br /><span style="font-weight: bold;">I want to get:</span><br
/> name| program | effective  |           tstamp           | rate <br
/>------+---------+------------+----------------------------+------<br/> jdoe | AAA     | 2006-07-01 | 2006-07-16
23:42:13.809214 |   20<br /> jdoe | BBB     | 2006-07-01 | 2006-07-16 23:42:13.809214 |   20<br /> jdoe | AAA     |
2006-08-16| 2006-08-25 11:57:17.394854 |   20<br /> jdoe | BBB     | 2006-08-16 | 2006-08-25 11:57:17.394854 |   20<br
/> jdoe | AAA     | 2006-09-01 | 2006-08-28 12:38:42.486513 |   20<br /> jdoe | BBB     | 2006-09-01 | 2006-08-28
12:38:42.486513|   20<br /><br />Basically, for effective='08-16-2006', it only gets the latest inserted<br />record
(usingtstamp) for that effective date, which is 2006-08-25 11:57: 17.394854.<br /><br />So what is the quickest way to
dothis?<br /><span style="font-weight: bold;">I can always do:</span><br />Select * from Table t where tstamp=(select
max(tstamp)from Table t2 where t2.name=t.name and t2.effective=t.effective )<br />but it takes so long since this is a
hugetable.<br /><br />Any suggestions?<br /> 

pgsql-sql by date:

Previous
From: "Henry Ortega"
Date:
Subject: Re: Trigger on Insert to Update only newly inserted fields?
Next
From: Richard Broersma Jr
Date:
Subject: Re: Fastest way to get max tstamp