Re: set-level update fails with unique constraint violation

From: David Fetter <david(at)fetter(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: set-level update fails with unique constraint violation
Date: 2009-12-31 16:04:58
Message-ID: 20091231160458.GD30171@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 31, 2009 at 10:52:20AM +0100, neuhauser+pgsql-general#postgresql(dot)org(at)sigpipe(dot)cz wrote:
> Hello,
>
> 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?

This will work in 8.5:

CREATE TABLE x (
i int NOT NULL UNIQUE DEFERRABLE INITIALLY DEFERRED
);
INSERT INTO x (i) VALUES (1), (2), (3);
UPDATE x SET i = i + 1;

Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris McDonald 2009-12-31 16:05:10 Query very slow when in plpgsql function
Previous Message Magnus Hagander 2009-12-31 15:52:31 Re: set-level update fails with unique constraint violation