pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: george young <gry@ll.mit.edu>
To: pgsql-sql@postgresql.org
Subject: how to update table to make dup values distinct
Date: Thu, 10 Nov 2005 10:58:18 -0500
Message-ID: <20051110105818.4dc51e8c.gry@ll.mit.edu> (raw)

[PostgreSQL 7.4RC2 on i686-pc-linux-gnu](I know, I know... must upgrade soon)

I have a table mytable like:
 i |  txt  
---+-------
 1 | the
 2 | the
 3 | rain
 4 | in
 5 | mainly
 6 | spain
 7 | stays
 8 | mainly
 9 | in

I want to update it, adding a ':' to txt so that each txt value is unique.
I don't care which entry gets changed.  I tried:

 update mytable set txt=mytable.txt || ':' from mytable t2 where mytable.txt=t2.txt and mytable.i=t2.i;

but this updated both duplicated entries.  

Um, there may sometimes be 3 or 4 duplicates, not just two.  For these, I can add multiple colons, or one each of an assortment of characters, say ':+*&^#'.

Performance does not matter here.  The real table has 30K rows, ~200 dups.
To clarify, I want to end up with something like:

 1 | the
 2 | the:
 3 | rain
 4 | in
 5 | mainly:
 6 | spain
 7 | stays
 8 | mainly
 9 | in:

-- George
-- 
"Are the gods not just?"  "Oh no, child.
What would become of us if they were?" (CSL)



view thread (3+ messages)  latest in thread

Message-ID: <20051110105818.4dc51e8c.gry@ll.mit.edu>
Permalink:  ../20051110105818.4dc51e8c.gry@ll.mit.edu/
Also on:    postgresql.org/message-id/20051110105818.4dc51e8c.gry@ll.mit.edu

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gry@ll.mit.edu
  Subject: Re: how to update table to make dup values distinct
  In-Reply-To: <20051110105818.4dc51e8c.gry@ll.mit.edu>

* 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