Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axMTh-0003YI-Tp for pgsql-bugs@arkaria.postgresql.org; Mon, 02 May 2016 22:38:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1axMTg-0007dP-NJ for pgsql-bugs@arkaria.postgresql.org; Mon, 02 May 2016 22:38:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1axMTf-0007dG-A2 for pgsql-bugs@postgresql.org; Mon, 02 May 2016 22:38:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axMTb-0005g8-Qg for pgsql-bugs@postgresql.org; Mon, 02 May 2016 22:38:06 +0000 MIME-Version: 1.0 Subject: BUG #14124: ON UPDATE CASCADE failure on repeated foreign key column To: pgsql-bugs@postgresql.org From: targen@gmail.com Date: Mon, 02 May 2016 22:37:20 +0000 Message-ID: <20160502223720.19110.71285@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 The following bug has been logged on the website: Bug reference: 14124 Logged by: Manuel Gómez Email address: targen@gmail.com PostgreSQL version: 9.4.7 Operating system: Ubuntu Linux 14.04 Description: Foreign keys with ON UPDATE CASCADE generate invalid UPDATE statements if a column is used multiple times on the referring side of the foreign key. postgres=# create table foo (x int, y int, unique (x, y)); CREATE TABLE postgres=# create table bar (z int, foreign key (z, z) references foo (x, y) on update cascade); CREATE TABLE postgres=# insert into foo values (42, 42); INSERT 0 1 postgres=# insert into bar values (42); INSERT 0 1 postgres=# update foo set x = 27, y = 27; ERROR: multiple assignments to same column "z" CONTEXT: SQL statement "UPDATE ONLY "bar" SET "z" = $1, "z" = $2 WHERE $3 OPERATOR(pg_catalog.=) "z" AND $4 OPERATOR(pg_catalog.=) "z"" I don't know whether this is expected behavior. Indeed it would make sense for the process to fail if the two referenced columns are set to different values, as it would be unclear, in this example, whether z should take its value from x or y. However, the cascading update should work when they are indeed equal, and not produce a malformed statement. I can work around this with manually defined triggers, but this can probably be fixed. I could provide more complete context for the practical situation in which this issue arises if motivation is required. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs