From: Travis Whitton <tinymountain@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Grabbing Newest Records From Duplicates
Date: Fri, 16 Mar 2007 10:28:48 -0500
Message-ID: <cf9b4f3e0703160828s2cc0b9v6c01db6e8634e37e@mail.gmail.com> (raw)
Given the following test table, I want to grab only the newest record and
disregard any older duplicates based on name. Is this the most efficient way
to do it? Will the indicies even make a difference? The table below
demonstrates a simple proof of concept. My final table will have millions of
records; however, the test I'm doing now does not seem to use the indicies
(probably because there are too few records?).
optin=# \d test
Table "public.test"
Column | Type | Modifiers
--------+---------+-----------
name | text |
time | date |
id | integer |
Indexes:
"idx_name" btree (name)
"idx_time" btree ("time")
optin=# explain select * from test t1 where not exists (select 1 from test
t2 where t2.name = t1.name and t2.time > t1.time);
Thanks,
Travis
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: tinymountain@gmail.com
Subject: Re: Grabbing Newest Records From Duplicates
In-Reply-To: <cf9b4f3e0703160828s2cc0b9v6c01db6e8634e37e@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