X-Original-To: pgsql-sql@postgresql.org Received: from jester.inquent.com (CPE00508b028d7d-CM00803785c5e0.cpe.net.cable.rogers.com [24.103.51.175]) by postgresql.org (Postfix) with ESMTP id B7BD5474E42 for ; Sat, 8 Mar 2003 16:33:06 -0500 (EST) Received: from [127.0.0.1] (localhost [127.0.0.1]) by jester.inquent.com (8.12.6/8.12.6) with ESMTP id h28LXMgv062678; Sat, 8 Mar 2003 16:33:23 -0500 (EST) (envelope-from rbt@rbt.ca) Subject: Re: Atomicity of UPDATE, interchanging values in unique column From: Rod Taylor To: daniel alvarez Cc: pgsql-sql@postgresql.org In-Reply-To: <32207.1047158233@www5.gmx.net> References: <32207.1047158233@www5.gmx.net> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-OAijuQGTRokxcSroH4LQ" Organization: Message-Id: <1047159202.28251.196.camel@jester> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 Date: 08 Mar 2003 16:33:22 -0500 X-Archive-Number: 200303/212 X-Sequence-Number: 12252 --=-OAijuQGTRokxcSroH4LQ Content-Type: text/plain Content-Transfer-Encoding: quoted-printable > UPDATE sometable SET unique_col =3D > CASE WHEN unique_col =3D firstvalue THEN secondvalue > ELSE firstvalue > END > WHERE unique_col =3D firstvalue > OR unique_col =3D secondvalue (See last comment) > BEGIN; > SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; >=20 > UPDATE sometable SET unique_col =3D firstvalue WHERE unique_col =3D secon= dvalue; > UPDATE sometable SET unique_col =3D secondvalue WHERE unique_col =3D firs= tvalue; >=20 > COMMIT; This one will always fail unless you DEFER unique constraints -- something we don't support with PostgreSQL, but some others do. > How can I interchange two values in a unique column? Am I missing somethi= ng > really > obvious (like a swap statement)? Is there any reason besides performance = for > not > making index accesses fully ACID-compliant? Doesn't MVCC require this > anyway? The first is what you want. PostgreSQL needs some work in the evaluation of unique indexes to properly support it. Namely, when it sees a conflict when inserting into the index, it needs to record the fact, and revisit the conflict at the end of the command.=20 Lots of work... --=20 Rod Taylor PGP Key: http://www.rbt.ca/rbtpub.asc --=-OAijuQGTRokxcSroH4LQ Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQA+amGh6DETLow6vwwRAjbyAJ9HVti4Pi82VHoyZikHDg/1JFgADQCghrpy Jtz4/ITTJAgi4ooVcY2Q+ZY= =8Mz1 -----END PGP SIGNATURE----- --=-OAijuQGTRokxcSroH4LQ--