X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 7AA29D1B4A7 for ; Mon, 1 Dec 2003 03:12:42 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 22520-07 for ; Sun, 30 Nov 2003 23:12:15 -0400 (AST) Received: from millenium.mst.co.jp (unknown [210.230.185.241]) by svr1.postgresql.org (Postfix) with ESMTP id 184C0D1B47A for ; Sun, 30 Nov 2003 23:12:11 -0400 (AST) Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id hB132gi28745; Mon, 1 Dec 2003 12:02:42 +0900 Message-ID: <021001c3b7b8$75896570$7201a8c0@mst1x5r347kymb> From: "Iain" To: "Burr, Colin" , References: <7D8D2AE3E5A9DB4C8D78DE0F950ABB510BDC3F56@miaxch01.herald.com> Subject: Re: Bug: Sequence generator insert Date: Mon, 1 Dec 2003 12:08:56 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.6 tagged_above=0.0 required=5.0 tests=BAYES_30, DEAR_SOMETHING, QUOTED_EMAIL_TEXT, REFERENCES X-Spam-Level: X-Archive-Number: 200311/351 X-Sequence-Number: 16166 I just re-read your message, and it occurred to me that for the second insert you may have provided an explicit value for the 'id', is that right? You may need to give more detail about the inserts. I'd be mildly surprised, but not concerned if the insert that failed used an explicit value for the id (ir didn't use the default) but still used (and therefore incremented) the sequence. Regards Iain ----- Original Message ----- From: "Burr, Colin" To: Sent: Wednesday, November 26, 2003 8:37 AM Subject: [SQL] Bug: Sequence generator insert > Dear Sir, > I found a sequence generator software bug associated with duplicate key > inserts that may be of interest to you. > > I first created a table with a primary key based on a sequence generator. > The following script provides an example. > > CREATE SEQUENCE "id_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 > cache 1; > REVOKE ALL on "id_seq" from PUBLIC; > GRANT ALL on "id_seq" to "administrator"; > > CREATE TABLE "example" ( > "id" integer DEFAULT nextval('id_seq'::text) NOT NULL, > "colum_name" character varying(15) NOT NULL, > Constraint "ex_pkey" Primary Key ("id") > ); > REVOKE ALL on "example" from PUBLIC; > GRANT ALL on "example" to "administrator"; > > When I tried to insert a record into the table where a duplicate record > already exists, predictably, the insert fails and the following error is > generated: > > 'ERROR: Cannot insert a duplicate key into unique index ex_pkey' > > However, even though the new record failed to be inserted into the table, > the sequence generator was still updated. > > The sequence generator should only be updated if the record is successfully > inserted into the table, and should not be updated if the insert fails. > > > Sincerely yours, > > Colin Burr > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings