duplicates

From: Allan Kelly <allan(dot)kelly(at)buildstore(dot)co(dot)uk>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: duplicates
Date: 2000-04-07 10:34:01
Message-ID: 38EDB999.EA91E2DB@buildstore.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a system bug which means that I have occasional dupicate entries in
my 'subscribers' table. I'm trying to find a query which performs something
like a 'where user_name is not unique' query.

At the moment we use this cludge:

select count(*), user_name from subscribers
group by user_name order by count;

(I'm surprised I can't add 'where count > 1' but it seems conditionals on
aggregate fields are not allowed).

This gives me a very long list with the 'not unique' entries at the bottom, eg

count | user_name
------+------------------
1 | bill.hicks
[ ..cut 9 zillion results.. ]
1 | margaret.thatcher
4 | linus.torvalds
9 | bill.gates

I then have to do

select oid from subscribers where user_name = 'linus.torvalds';

and delete all but one of the records. Is there a better way to do this?
And yes, we're working on a system fix to avoid the problem in the 1st place!

TIA, al.

--

# Allan Kelly http://www.plotsearch.co.uk
# (+44) (0)131 524 8500
# allan(dot)kelly(at)buildstore(dot)co(dot)uk(dot)(dot)(dot) ..
# /Software Engineer/i . . . . .
# ------------------------------ * . . . . .
# "If you are a Visual Basic programmer, * . . .
# these details are none of your business." * . . .
# Mr Bunny's Guide to Active X, by Carlton Egremont III * . .
# ------------------------------ vi: set noet tw=80 sts=4 ts=8 : .

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Patrik Kudo 2000-04-07 11:27:38 Re: duplicates
Previous Message tjk@tksoft.com 2000-04-07 09:39:00 Re: update only if single row