From: | Adriaan Joubert <a(dot)joubert(at)albourne(dot)com> |
---|---|
To: | Gary Hoffman <ghoffman(at)ucsd(dot)edu> |
Cc: | pgsql-general(at)hub(dot)org |
Subject: | Re: [GENERAL] Selecting duplicates |
Date: | 1999-08-06 07:45:11 |
Message-ID: | 37AA9287.EEA3867B@albourne.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Gary Hoffman wrote:
>
> Somehow, I've managed to get duplicate entries in my soon-to-be primary
> key field. How can I select for duplicates in a field? I know how to
> select for blank and NULL, but duplicates escape me.
Sorry, I only know complicated ways of doing this. The way I usually do
it is to create a temporary table:
create temp table tmp (id int4, cnt int4);
insert into tmp select id, count(*) from <table> group by id;
Then look at all entries in tmp where cnt is bigger than 1. Deciding
which entry to throw out is tougher. I have been working with the
assumption that oids are (usually anyway) assigned in ascending order.
Don't actually know whether that is true. But if they are you can delete
everything but the entry with the highest (or lowest) oid.
Hope this helps,
Adriaan
From | Date | Subject | |
---|---|---|---|
Next Message | Alexandre Fayolle | 1999-08-06 08:01:56 | Database on read only directory |
Previous Message | Gary Hoffman | 1999-08-06 07:14:27 | Selecting duplicates |