pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Edward W. Rouse <erouse@comsquared.com>
To: pgsql-sql@postgresql.org
Subject: Re: Duplicate rows
Date: Tue, 10 Aug 2010 16:42:48 -0400
Message-ID: <00c801cb38cc$9814b990$c83e2cb0$@com> (raw)
In-Reply-To: <20100810194433.GA2021@tux>
References: <00b701cb38c0$d64fc760$82ef5620$@com>
	<20100810194433.GA2021@tux>

I am trying to test this but get an error.

select ctid, * from test where id < 3000000 order by id, ctid;
ERROR:  could not identify an ordering operator for type tid
HINT:  Use an explicit ordering operator or modify the query.

If I do a select I get this:

select ctid, * from test where id < 3000000 order by id;      
  ctid   |   id    | activated | wake_up_time 

(108,22) |     316 | f         |              
 (36,17) |     316 | f         |              
(used 2 rows only for brevity

And when I tried max(ctid) I got:

ERROR:  function max(tid) does not exist
HINT:  No function matches the given name and argument types. You may need
to add explicit type casts.

I appreciate all the help and this feels like I'm almost there.
Thanks


Edward W. Rouse

-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of Andreas Kretschmer
Sent: Tuesday, August 10, 2010 3:45 PM
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] Duplicate rows

Edward W. Rouse <erouse@comsquared.com> wrote:

> Is there any way to remove a duplicate row from a table? Not my db but I
have
> to work with it. On version 7.4 right now.
> 

How to select the right records?

You can try to use the ctid-column, see my simple example:

test=# select * from dups ;
 i
---
 1
 1
 1
 2
 2
 3
 4
(7 Zeilen)

Zeit: 0,145 ms
test=*# delete from dups where (ctid, i) not in (select max(ctid), i from
dups group by i);
DELETE 3
Zeit: 0,378 ms
test=*# select * from dups ;
 i
---
 1
 2
 3
 4
(4 Zeilen)



Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."   (unknown)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql




view thread (12+ messages)  latest in thread

Message-ID: <00c801cb38cc$9814b990$c83e2cb0$@com>
Permalink:  ../00c801cb38cc$9814b990$c83e2cb0$@com/
Also on:    postgresql.org/message-id/00c801cb38cc$9814b990$c83e2cb0$@com

 · 

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: erouse@comsquared.com
  Subject: Re: Duplicate rows
  In-Reply-To: <00c801cb38cc$9814b990$c83e2cb0$@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