pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Henry Ortega <juandelacruz@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Fastest way to get max tstamp
Date: Mon, 28 Aug 2006 14:10:02 -0400
Message-ID: <2bffcc330608281110j404e3fd1q9d6d27a6a97ad31d@mail.gmail.com> (raw )
This is my table:
name | program | effective | tstamp | rate
------+---------+------------+----------------------------+------
jdoe | AAA | 2006-07-01 | 2006-07-16 23:42:13.809214 | 20
jdoe | BBB | 2006-07-01 | 2006-07-16 23:42:13.809214 | 20
jdoe | AAA | 2006-08-16 | 2006-08-25 11:56:50.380575 | 20
jdoe | BBB | 2006-08-16 | 2006-08-25 11:56:50.380575 | 20
jdoe | AAA | 2006-08-16 | 2006-08-25 11:57:17.394854 | 20
jdoe | BBB | 2006-08-16 | 2006-08-25 11:57:17.394854 | 20
jdoe | AAA | 2006-09-01 | 2006-08-28 12:38:42.486513 | 20
jdoe | BBB | 2006-09-01 | 2006-08-28 12:38:42.486513 | 20
I want to get:
name | program | effective | tstamp | rate
------+---------+------------+----------------------------+------
jdoe | AAA | 2006-07-01 | 2006-07-16 23:42:13.809214 | 20
jdoe | BBB | 2006-07-01 | 2006-07-16 23:42:13.809214 | 20
jdoe | AAA | 2006-08-16 | 2006-08-25 11:57:17.394854 | 20
jdoe | BBB | 2006-08-16 | 2006-08-25 11:57:17.394854 | 20
jdoe | AAA | 2006-09-01 | 2006-08-28 12:38:42.486513 | 20
jdoe | BBB | 2006-09-01 | 2006-08-28 12:38:42.486513 | 20
Basically, for effective='08-16-2006', it only gets the latest inserted
record (using tstamp) for that effective date, which is 2006-08-25 11:57:
17.394854.
So what is the quickest way to do this?
I can always do:
Select * from Table t where tstamp=(select max(tstamp) from Table t2 where
t2.name=t.name and t2.effective=t.effective)
but it takes so long since this is a huge table.
Any suggestions?
view thread (2+ messages) latest in thread
Message-ID: <2bffcc330608281110j404e3fd1q9d6d27a6a97ad31d@mail.gmail.com>
Permalink: ../2bffcc330608281110j404e3fd1q9d6d27a6a97ad31d@mail.gmail.com/
Also on: postgresql.org/message-id/2bffcc330608281110j404e3fd1q9d6d27a6a97ad31d@mail.gmail.com
copy link · copy postgr.es
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-sql@postgresql.org
Cc: juandelacruz@gmail.com
Subject: Re: Fastest way to get max tstamp
In-Reply-To: <2bffcc330608281110j404e3fd1q9d6d27a6a97ad31d@mail.gmail.com>
* 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