pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Allan Kelly <allan.kelly@buildstore.co.uk>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: duplicates
Date: Fri, 07 Apr 2000 11:34:01 +0100
Message-ID: <38EDB999.EA91E2DB@buildstore.co.uk> (raw)

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.kelly@buildstore.co.uk...     ..
 # /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  : .



view thread (5+ messages)  latest in thread

Message-ID: <38EDB999.EA91E2DB@buildstore.co.uk>
Permalink:  ../38EDB999.EA91E2DB@buildstore.co.uk/
Also on:    postgresql.org/message-id/38EDB999.EA91E2DB@buildstore.co.uk

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: allan.kelly@buildstore.co.uk
  Subject: Re: duplicates
  In-Reply-To: <38EDB999.EA91E2DB@buildstore.co.uk>
  References: <38EDB999.EA91E2DB@buildstore.co.uk>

* 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