Re: set-level update fails with unique constraint violation - Mailing list pgsql-general

From Roman Neuhauser
Subject Re: set-level update fails with unique constraint violation
Date
Msg-id 20100105195232.GF1484@isis.sigpipe.cz
Whole thread Raw
In response to Re: set-level update fails with unique constraint violation  (Jayadevan M <Jayadevan.Maymala@ibsplc.com>)
Responses Re: set-level update fails with unique constraint violation  (Dean Rasheed <dean.a.rasheed@googlemail.com>)
List pgsql-general
# Jayadevan.Maymala@ibsplc.com / 2010-01-04 10:03:29 +0530:
> From:   neuhauser+pgsql-general#postgresql.org@sigpipe.cz
> >
> > this fails with "duplicate key value":
> >
> >     CREATE TABLE x (
> >       i INT NOT NULL UNIQUE
> >     );
> >     INSERT INTO x (i) VALUES (1), (2), (3);
> >     UPDATE x SET i = i + 1;
> >
> > are there any plans to make this work?
>
> Hi,
> This seems to work..
> UPDATE x  set i=i+1
> from  (select i as m from x order by m desc) y   where x.i = y.m
> Jayadevan

Thanks, that nicely achieves the illusion of atomic immediate checking.

--
Roman Neuhauser

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: PostgreSQL Write Performance
Next
From: Tim Uckun
Date:
Subject: Re: PostgreSQL Write Performance