Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wnt5r-0002eb-Q4 for pgsql-bugs@arkaria.postgresql.org; Fri, 23 May 2014 17:17:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Wnt5q-0008GX-JL for pgsql-bugs@arkaria.postgresql.org; Fri, 23 May 2014 17:17:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Wnt5p-0008GQ-9U for pgsql-bugs@postgresql.org; Fri, 23 May 2014 17:17:17 +0000 Received: from hermes.ort.edu.uy ([164.73.96.24]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wnt5g-0008BH-2m for pgsql-bugs@postgresql.org; Fri, 23 May 2014 17:17:15 +0000 Received: from hermes.ort.edu.uy (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D0B38138091 for ; Fri, 23 May 2014 14:17:04 -0300 (UYT) Received: from archie.ort.edu.uy (unknown [192.168.20.22]) by hermes.ort.edu.uy (Postfix) with ESMTP id B740113808C for ; Fri, 23 May 2014 14:17:04 -0300 (UYT) Received: from [172.30.10.6] (unknown [172.30.10.6]) by archie.ort.edu.uy (Postfix) with ESMTP id 1C7CC1FA43 for ; Fri, 23 May 2014 14:17:05 -0300 (UYT) Message-ID: <537F827F.8030303@ort.edu.uy> Date: Fri, 23 May 2014 14:16:47 -0300 From: rodriguez User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: BUG #10429: the same update return different result References: <20140523074125.2687.92046@wrigleys.postgresql.org> In-Reply-To: <20140523074125.2687.92046@wrigleys.postgresql.org> Content-Type: multipart/alternative; boundary="------------020906030000030901000300" X-TM-AS-MML: No X-TM-AS-Product-Ver: IMSVA-8.2.0.1679-7.5.0.1017-20712.000 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSVA-8.2.0.1679-7.5.1017-20712.000 X-TMASE-Result: 10--13.327400-5.000000 X-TMASE-MatchedRID: 66BtJSlJtHeWF7VpPCfWvGYQJPSPOa+9nlcj8KkChv6g71w0L+ciHqrC DL9ce7kLu9Q93luDLD9sG7r4Qh7N3IzjknOM+UJoLcVjbs+keawCXItyeXwoVARLPkT8qxoZHI0 v3Fgc2rNVlU1PWtrBsxD3+0w1DhqKc3ewuwbSaG4Nht78/JfyBHpFpKkcmr8ApEgU1whKQMXS7F RggdpBP/PtClEs9sT6lY5qr7f6fHJBldmDYjwlpmlsV2yRfONi+1Bysa1PtqRwcvwnIbXwMxtr8 MMczWMdRF8J0whn5t2zLD5kmcW6ZBrHeFABLxXVUfLlptXrqAlNuXvEUXlK+KRGASDuetHK660+ DqvfilOCIg7tJ//usRShFzOcYnCAm/y00tE9StaqwLRGGOyndXlEDb1OO87oEeHflL4ZdKr9Vaa 04yzrEd5ZokMflaoNOoGxp0fynb4cDDLReGt4PfmUDxpFogQXo8WMkQWv6iXoC+VlRHhOyAGLeS ok4rrZP9xmfnR7MeoNlf30fAUOwryah9aCYUCHOd6GS2yF6+MKzWoY4+Io/IWLjAWo3m1uzJX5d hOUSvwzQmp2kz0u7kSc77GavC58i6thCpGlbuHrfYYCWxkad6WNTl0Tl/i/ X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------020906030000030901000300 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit El 23/05/2014 04:41 a.m., chuisiniu@hotmail.com escribió: > The following bug has been logged on the website: > > Bug reference: 10429 > Logged by: zhanglong > Email address: chuisiniu@hotmail.com > PostgreSQL version: 9.3.4 > Operating system: window7 32bit > Description: > > E:\postgresql-9.4beta1\db\bin>psql postgres > psql (9.4beta1) > Type "help" for help. > > postgres=# drop table t1; > DROP TABLE > postgres=# create table t1(c1 int primary key); > CREATE TABLE > postgres=# insert into t1 values (1);insert into t1 values (2);update t1 set > c1 = c1 +1; > INSERT 0 1 > INSERT 0 1 > ERROR: duplicate key value violates unique constraint "t1_pkey" > DETAIL: Key (c1)=(2) already exists. > postgres=# select * from t1; > c1 > ---- > 1 > 2 > (2 rows) > > > postgres=# > postgres=# drop table t1; > DROP TABLE > postgres=# create table t1(c1 int primary key); > CREATE TABLE > postgres=# insert into t1 values (2);insert into t1 values (1);update t1 set > c1 = c1 +1; > INSERT 0 1 > INSERT 0 1 > UPDATE 2 > postgres=# select * from t1; > c1 > ---- > 3 > 2 > (2 rows) > > The data is all the same except the order I insert it,but the update get > different result.From the source code, it seems that db update the tuple > first found out. > > the first case you insert row number 1 value 1 row number 2 value 2 when update row number 1 value 1 + 1=2 produces duplicate the second case you insert row number 1 value 2 row number 2 value 1 when update row number 1 value 2 + 1=3 row number 1 value 1 + 1=2 OK!!! perhaps you need define your constraint deferrable http://www.postgresql.org/docs/9.3/static/sql-createtable.html DEFERRABLE NOT DEFERRABLE This controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command. Checking of constraints that are deferrable can be postponed until the end of the transaction (using the SET CONSTRAINTS command). NOT DEFERRABLE is the default. Currently, only UNIQUE, PRIMARY KEY, EXCLUDE, and REFERENCES (foreign key) constraints accept this clause. NOT NULL and CHECK constraints are not deferrable. INITIALLY IMMEDIATE INITIALLY DEFERRED If a constraint is deferrable, this clause specifies the default time to check the constraint. If the constraint is INITIALLY IMMEDIATE, it is checked after each statement. This is the default. If the constraint is INITIALLY DEFERRED, it is checked only at the end of the transaction. The constraint check time can be altered with the SET CONSTRAINTS command. --------------020906030000030901000300 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
El 23/05/2014 04:41 a.m., chuisiniu@hotmail.com escribió:
The following bug has been logged on the website:

Bug reference:      10429
Logged by:          zhanglong
Email address:      chuisiniu@hotmail.com
PostgreSQL version: 9.3.4
Operating system:   window7 32bit
Description:        

E:\postgresql-9.4beta1\db\bin>psql postgres
psql (9.4beta1)
Type "help" for help.

postgres=# drop table t1;
DROP TABLE
postgres=# create table t1(c1 int primary key);
CREATE TABLE
postgres=# insert into t1 values (1);insert into t1 values (2);update t1 set
c1 = c1 +1;
INSERT 0 1
INSERT 0 1
ERROR:  duplicate key value violates unique constraint "t1_pkey"
DETAIL:  Key (c1)=(2) already exists.
postgres=# select * from t1;
 c1
----
  1
  2
(2 rows)


postgres=#
postgres=# drop table t1;
DROP TABLE
postgres=# create table t1(c1 int primary key);
CREATE TABLE
postgres=# insert into t1 values (2);insert into t1 values (1);update t1 set
c1 = c1 +1;
INSERT 0 1
INSERT 0 1
UPDATE 2
postgres=# select * from t1;
 c1
----
  3
  2
(2 rows)

The data is all the same except the order I insert it,but the update get
different result.From the source code, it seems that db update the tuple
first found out.


the first case you insert
row number 1    value  1
row number 2    value  2
 when update
row number 1    value  1 + 1=2  produces duplicate

the second case you insert
row number 1    value  2
row number 2    value  1
 when update
row number 1    value  2 + 1=3
row number 1    value  1 + 1=2
OK!!!

perhaps you need define your constraint deferrable

http://www.postgresql.org/docs/9.3/static/sql-createtable.html
DEFERRABLE
NOT DEFERRABLE

This controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command. Checking of constraints that are deferrable can be postponed until the end of the transaction (using the SET CONSTRAINTS command). NOT DEFERRABLE is the default. Currently, only UNIQUE, PRIMARY KEY, EXCLUDE, and REFERENCES (foreign key) constraints accept this clause. NOT NULL and CHECK constraints are not deferrable.

INITIALLY IMMEDIATE
INITIALLY DEFERRED

If a constraint is deferrable, this clause specifies the default time to check the constraint. If the constraint is INITIALLY IMMEDIATE, it is checked after each statement. This is the default. If the constraint is INITIALLY DEFERRED, it is checked only at the end of the transaction. The constraint check time can be altered with the SET CONSTRAINTS command.


--------------020906030000030901000300--