How to delete completely duplicate rows

Started by Janek Sendrowskiover 12 years ago5 messagesgeneral
Jump to latest
#1Janek Sendrowski
janek12@web.de

Hi,
 
I want to delete duplicates in my table. I've dropped the unique constraint to insert my data.
My id value is a hash calculated witch the values of the two other columns.
So I want to delete all columns, which are indentical, but keeping one.
 
DELETE FROM table t1 USING table t2 WHERE t1.id = t2.id AND t1.ctid > t2.ctid

But the oids aren't unique enough.
What else could I do?

Janek

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

#2Erik Darling
edarling80@gmail.com
In reply to: Janek Sendrowski (#1)
Re: How to delete completely duplicate rows

With C as (
Select row_number() over partition by (list, all, columns, here order by
oid) as rn
)
Delete
From C
Where rn > 1;
On Jan 1, 2014 7:15 AM, "Janek Sendrowski" <janek12@web.de> wrote:

Show quoted text

Hi,

I want to delete duplicates in my table. I've dropped the unique
constraint to insert my data.
My id value is a hash calculated witch the values of the two other columns.
So I want to delete all columns, which are indentical, but keeping one.

DELETE FROM table t1 USING table t2 WHERE t1.id = t2.id AND t1.ctid >
t2.ctid

But the oids aren't unique enough.
What else could I do?

Janek

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

#3bricklen
bricklen@gmail.com
In reply to: Janek Sendrowski (#1)
Re: How to delete completely duplicate rows

On Wed, Jan 1, 2014 at 4:14 AM, Janek Sendrowski <janek12@web.de> wrote:

I want to delete duplicates in my table. I've dropped the unique
constraint to insert my data.
My id value is a hash calculated witch the values of the two other columns.
So I want to delete all columns, which are indentical, but keeping one.

DELETE FROM table t1 USING table t2 WHERE t1.id = t2.id AND t1.ctid >
t2.ctid

But the oids aren't unique enough.
What else could I do?

http://postgres.cz/wiki/PostgreSQL_SQL_Tricks#Delete_duplicate_rows_with_window_analytic_functions
http://wiki.postgresql.org/wiki/Deleting_duplicates

#4Janek Sendrowski
janek12@web.de
In reply to: bricklen (#3)
Re: How to delete completely duplicate rows

Thanks!
It's working
 
Janek

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

#5Merlin Moncure
mmoncure@gmail.com
In reply to: Janek Sendrowski (#4)
Re: How to delete completely duplicate rows

On Thu, Jan 2, 2014 at 4:33 AM, Janek Sendrowski <janek12@web.de> wrote:

Thanks!
It's working

you can do it without listing columns via:

select *, row_number() over(partition by c) from c;

emphasis on 'partition by c'.

merlin

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