Modifiable sequence column?

From: Leif K-Brooks <eurleif(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Modifiable sequence column?
Date: 2005-08-17 01:01:41
Message-ID: 85d9a9090508161801b118109@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I want a column which is like a SERIAL, except that values can be
changed after insertion without anything breaking. In other words, I
don't want an error like this one to occur:

database=> CREATE TABLE foo (bar SERIAL UNIQUE);
CREATE TABLE
database=> INSERT INTO foo(bar) VALUES(DEFAULT);
INSERT 25410 1
database=> UPDATE foo SET bar=2 WHERE bar=1;
UPDATE 1
database=> INSERT INTO foo(bar) VALUES(DEFAULT);
ERROR: duplicate key violates unique constraint "foo_bar_key"

I've tried defining bar as (SELECT MAX(bar) + 1 FROM foo), but that
breaks concurrency. Is there a solution to this problem that works?

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Bruno Wolff III 2005-08-17 04:48:50 Re: Modifiable sequence column?
Previous Message Oliver Elphick 2005-08-16 22:16:42 Re: how to rename an unnamed uniqueness constraint?