Re: unique key problem on update

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: unique key problem on update
Date: 2013-09-20 16:26:58
Message-ID: l1ht05$9cq$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Gary Stainburn wrote on 20.09.2013 18:07:
> I want to add a new page after page 2 so I try to increase the sequence number
> of each row from page 3 onwards to make space in the sequence for the new
> record. However, I get duplicate key errors when I try. Can anyone suggest
> how I get round this.
>
> Also, the final version will be put onto a WordPress web site which means I
> will have to port it to MYSQL which I don't know, so any solution that will
> work with both systems would be a great help.
>

You need to define the primary key as deferrable:

create table skills_pages
(
sp_id serial not null,
sp_sequence integer not null,
sp_title character varying(80),
sp_narative text,
primary key (sp_id) deferrable
);

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2013-09-20 16:30:50 Re: unique key problem on update
Previous Message Gary Stainburn 2013-09-20 16:07:55 unique key problem on update