Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VN3FX-0002DC-9v for pgsql-sql@arkaria.postgresql.org; Fri, 20 Sep 2013 16:08:07 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VN3FW-0006Ot-1Q for pgsql-sql@arkaria.postgresql.org; Fri, 20 Sep 2013 16:08:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VN3FV-0006Om-0x for pgsql-sql@postgresql.org; Fri, 20 Sep 2013 16:08:05 +0000 Received: from hub.ringways.co.uk ([88.211.105.30] helo=mail.ringways.co.uk) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VN3FN-0006lF-Pj for pgsql-sql@postgresql.org; Fri, 20 Sep 2013 16:08:04 +0000 Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1VN3FM-0002WM-6e for pgsql-sql@postgresql.org; Fri, 20 Sep 2013 17:07:56 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: "pgsql-sql@postgresql.org" Subject: unique key problem on update Date: Fri, 20 Sep 2013 17:07:55 +0100 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201309201707.56028.gary.stainburn@ringways.co.uk> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hi folks. I've got the table and data shown below. 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. Ta Gary stainburn=# \d skills_pages Table "public.skills_pages" Column | Type | Modifiers -------------+-----------------------+-------------------------------------------------------------- sp_id | integer | not null default nextval('skills_pages_sp_id_seq'::regclass) sp_sequence | integer | not null sp_title | character varying(80) | sp_narative | text | Indexes: "skills_pages_pkey" PRIMARY KEY, btree (sp_id) "skills_pages_sequence" UNIQUE, btree (sp_sequence) stainburn=# select * from skills_pages; sp_id | sp_sequence | sp_title | sp_narative -------+-------------+------------------+------------- 1 | 10 | Departments | 2 | 20 | Interest Groups | 3 | 30 | Customer Focused | 4 | 40 | Business Roles | 5 | 50 | Commercial | 6 | 60 | People Oriented | 7 | 70 | Engineering | (7 rows) stainburn=# update skills_pages set sp_sequence=sp_sequence+10 where sp_sequence >= 30; ERROR: duplicate key value violates unique constraint "skills_pages_sequence" stainburn=# -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql