Re: How to delete completely duplicate rows

Lists: pgsql-general
From: "Janek Sendrowski" <janek12(at)web(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: How to delete completely duplicate rows
Date: 2014-01-01 12:14:10
Message-ID: trinity-eb3eb934-ffcb-42f8-bb42-7841c964032f-1388578450214@3capp-webde-bs32
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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


From: Erik Darling <edarling80(at)gmail(dot)com>
To: Janek Sendrowski <janek12(at)web(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to delete completely duplicate rows
Date: 2014-01-01 12:41:21
Message-ID: CAO+EYw+GTLwb8trWwDxVCJ2jU-CYPYANhUEppiO9NyD1LpW3pg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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(at)web(dot)de> wrote:

> 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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>


From: bricklen <bricklen(at)gmail(dot)com>
To: Janek Sendrowski <janek12(at)web(dot)de>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to delete completely duplicate rows
Date: 2014-01-01 16:45:54
Message-ID: CAGrpgQ-g9m0YTAupqe6VTjg6tb65cYHwZFrTAnpyU0FjpFnWsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wed, Jan 1, 2014 at 4:14 AM, Janek Sendrowski <janek12(at)web(dot)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


From: "Janek Sendrowski" <janek12(at)web(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to delete completely duplicate rows
Date: 2014-01-02 10:33:39
Message-ID: trinity-0e2b23c7-a6df-4906-bd57-3a8d5b3892a6-1388658819256@3capp-webde-bs42
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Thanks!
It's working
 
Janek


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Janek Sendrowski <janek12(at)web(dot)de>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to delete completely duplicate rows
Date: 2014-01-02 16:56:01
Message-ID: CAHyXU0xfa6kSbtGenFTZna6a2UT9nQoO65TV=b1jKGY+QZEHvA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Thu, Jan 2, 2014 at 4:33 AM, Janek Sendrowski <janek12(at)web(dot)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