Received: from mail1.hub.org (webmail.hub.org [216.126.85.1]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f57GsVE08019 for ; Thu, 7 Jun 2001 12:54:31 -0400 (EDT) (envelope-from gml1@coldresist.com) Received: from coldresist.com (cr271446-a.rchmd1.bc.wave.home.com [24.113.128.171]) by mail1.hub.org (8.11.3/8.11.1) with ESMTP id f57GsU208007 for ; Thu, 7 Jun 2001 12:54:30 -0400 (EDT) (envelope-from gml1@coldresist.com) Received: from idyllic.coldresist.com ([192.168.0.7]) by coldresist.com (8.11.2/8.11.2) with ESMTP id f57GuPx18788 for ; Thu, 7 Jun 2001 09:56:26 -0700 Message-Id: <5.1.0.14.0.20010607095946.00ac7e90@coldresist.com> X-Sender: gml1@coldresist.com X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Thu, 07 Jun 2001 09:59:50 -0700 To: pgsql-sql@postgresql.org From: Gerald Gutierrez Subject: Are SQL commands "atomic" ? Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200106/108 X-Sequence-Number: 3328 I'm using 7.1.1 right now, and have the following table: id | s ----+------- 1 | alpha 2 | beta 3 | gamma 4 | delta (4 rows) I'd like to switch the id of "beta" to 3 and the id of "gamma" to 2 ("flip" them). Since id is the PK, it must remain unique and so I can't just set the two lines using two UPDATEs. My solution is: UPDATE t1 SET id=id#1 WHERE id=2 OR id=3; -- # is the XOR operator where 2#1=3 and 3#1=2. One statement will change both values as I want. But when I run the statement, the server replies with: ERROR: Cannot insert a duplicate key into unique index t1_pkey If the statement is "atomic", then if the statement succeeds, the IDs will be unique and the error is incorrect. Does this imply that SQL statements are not actually atomic?