Search Postgresql Archives

Re: set-level update fails with unique constraint violation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



# Jayadevan.Maymala@xxxxxxxxxx / 2010-01-04 10:03:29 +0530:
> From:   neuhauser+pgsql-general#postgresql.org@xxxxxxxxxx
> > 
> > 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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux