X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4B51CD907F for ; Fri, 11 Nov 2005 10:42:48 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 70275-06 for ; Fri, 11 Nov 2005 14:42:44 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by svr1.postgresql.org (Postfix) with ESMTP id ABA3DD6D19 for ; Fri, 11 Nov 2005 10:42:46 -0400 (AST) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by svr2.postgresql.org (Postfix) with ESMTP id A46DDF0CB9 for ; Fri, 11 Nov 2005 14:42:50 +0000 (GMT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Eaa5C-0001vx-Ct for pgsql-sql@postgresql.org; Fri, 11 Nov 2005 15:40:50 +0100 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Nov 2005 15:40:50 +0100 Received: from hf0923x by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Nov 2005 15:40:50 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Re: how to update table to make dup values distinct Date: 11 Nov 2005 15:38:49 +0100 Organization: Linux Private Site Lines: 47 Message-ID: <871x1n5jwm.fsf@srv.protecting.net> References: <20051110105818.4dc51e8c.gry@ll.mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.003 required=5 tests=[AWL=0.003] X-Spam-Score: 0.003 X-Spam-Level: X-Archive-Number: 200511/103 X-Sequence-Number: 23354 In article <20051110105818.4dc51e8c.gry@ll.mit.edu>, george young writes: > [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: Try the following: UPDATE mytable SET txt = txt || substring ('::::::::::::::::' for ( SELECT count(*) FROM mytable t1 WHERE t1.txt = mytable.txt AND t1.i < mytable.i )::int)