X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4926452B0F for ; Mon, 25 Jul 2005 09:58:59 -0300 (ADT) 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 65482-06 for ; Mon, 25 Jul 2005 12:58:50 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 033EA52B6C for ; Mon, 25 Jul 2005 09:58:47 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 9BC8030B42; Mon, 25 Jul 2005 15:05:54 +0200 (MET DST) From: jacekp@poczta.wprost.pl X-Newsgroups: pgsql.sql Subject: update vs unique index Date: 25 Jul 2005 05:58:43 -0700 Organization: http://groups.google.com Lines: 31 Message-ID: <1122296323.723165.27560@o13g2000cwo.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: o13g2000cwo.googlegroups.com; posting-host=62.111.149.146; posting-account=5pOcrgwAAAAea_pm-cR3TwkmTPBCVBAc To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.178 tagged_above=0 required=5 tests=NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200507/221 X-Sequence-Number: 22199 Consider such table: CREATE TABLE test (idx integer); populated by following statements: INSERT INTO test VALUES (1); INSERT INTO test VALUES (2); INSERT INTO test VALUES (3); since idx schould be unique, we need an index CREATE UNIQUE INDEX i_test ON test(idx); Following SQL command fails: UPDATE test SET idx = idx + 1; I can imagine why it fails. Update operates on first row, making 2 out of 1 and that collides with second row (which has 2 as its value already). However, when you look at the update efect as a whole uniqueness is preserved, so index schould not veto update. My question is: is there a chance to bypass this behaviour? Something like controlling the order in which rows go into update. If update would start from last row, it would be successful for sure. regards, -- Jacek Prucia