update inside transaction violates unique constraint?

From: Andrew Sullivan <sullivana(at)bpl(dot)on(dot)ca>
To: user Postgresql ML <pgsql-general(at)postgresql(dot)org>
Subject: update inside transaction violates unique constraint?
Date: 2000-09-26 20:43:02
Message-ID: 20000926164302.G22812@bpl.on.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I've probably just overlooked something, but a (quick-ish, I admit)
look at the ML archive, my own memory, and the TODO list isn't
turning anything up. Flame me if I'm wasting everyone's time (well,
with this. We needn't get into other things, or I'll never get out
of asbestos).

I have a table which keeps some name and IP pairs:

\d name_and_ip
Table "name_and_ip"
Attribute | Type | Modifier
-----------+-------------+----------
name | varchar(30) | not null
ip | inet | not null
Indices: name_and_ip_pairs,
name_and_ip_pkey

Now, I have some values

name | ip
------+-----------------
foo | 192.168.186.248
bar | 192.168.186.249
(2 rows)

If I do

#UPDATE name_and_ip set ip = '192.168.186.249' where name = 'foo';

I get an error (which is good). But, if I do

#BEGIN;
#SELECT * FROM name_and_ip WHERE name = 'foo' OR name = 'bar' FOR
UPDATE;
#UPDATE name_and_ip SET ip = '192.168.186.249' where name = 'foo';
UPDATE 1
#COMMIT;
COMMIT

#SELECT * FROM name_and_ip WHERE name = 'foo' OR name = 'bar';
name | ip
------+-----------------
bar | 192.168.186.249
foo | 192.168.186.249
(2 rows)

Have I done something wrong here, or have I stumbled on a bug?
Shouldn't this cause an error and a rollback?

--
Andrew Sullivan Computer Services
<sullivana(at)bpl(dot)on(dot)ca> Burlington Public Library
+1 905 639 3611 x158 2331 New Street
Burlington, Ontario, Canada L7R 1J4

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2000-09-26 20:52:11 Re: FreeBSD Softupdates??
Previous Message Lamar Owen 2000-09-26 20:38:41 Re: Re: web programming