Re: set-level update fails with unique constraint violation

From: Roman Neuhauser <neuhauser+pgsql-general#postgresql(dot)org(at)sigpipe(dot)cz>
To: Jayadevan M <Jayadevan(dot)Maymala(at)ibsplc(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: set-level update fails with unique constraint violation
Date: 2010-01-05 19:52:33
Message-ID: 20100105195232.GF1484@isis.sigpipe.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

# Jayadevan(dot)Maymala(at)ibsplc(dot)com / 2010-01-04 10:03:29 +0530:
> From: neuhauser+pgsql-general#postgresql(dot)org(at)sigpipe(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Antonio Goméz Soto 2010-01-05 19:56:32 Re: Using table name in column for joining
Previous Message Frank Joerdens 2010-01-05 19:36:26 Re: reason for default PGSTAT_ACTIVITY_SIZE