Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axNRc-0007Wm-P6 for pgsql-bugs@arkaria.postgresql.org; Mon, 02 May 2016 23:40:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1axNRb-0007Z3-Pl for pgsql-bugs@arkaria.postgresql.org; Mon, 02 May 2016 23:40:03 +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 1axNRa-0007Yu-CY for pgsql-bugs@postgresql.org; Mon, 02 May 2016 23:40:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1axNRS-0006vF-T0 for pgsql-bugs@postgresql.org; Mon, 02 May 2016 23:40:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u42NdqlN018489; Mon, 2 May 2016 19:39:52 -0400 From: Tom Lane To: targen@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14124: ON UPDATE CASCADE failure on repeated foreign key column In-reply-to: <20160502223720.19110.71285@wrigleys.postgresql.org> References: <20160502223720.19110.71285@wrigleys.postgresql.org> Comments: In-reply-to targen@gmail.com message dated "Mon, 02 May 2016 22:37:20 -0000" Date: Mon, 02 May 2016 19:39:52 -0400 Message-ID: <18488.1462232392@sss.pgh.pa.us> X-Pg-Spam-Score: -2.9 (--) 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 targen@gmail.com writes: > postgres=# create table bar (z int, foreign key (z, z) references foo (x, y) > on update cascade); Hmm. Such a constraint is specifically forbidden by the SQL standard, see SQL:2011 11.8 syntax rule 8: Each referencing column shall identify a column of the referencing table, and the same column shall not be identified more than once. Can you produce a convincing use-case for this structure? > 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. It would be difficult to support that, AFAICS, because the FK enforcement queries do not depend on things like whether the specific values involved are equal. Nor would one generally expect that an FK constraint should be allowed to restrict what can be stored in the referenced table. Moreover, it's not even real clear to me that there is a well defined notion of "equal" in such a situation. If x and y are of different types, it's possible they would have different equality rules. (This is somewhat constrained by the fact that z would have to have equality operators in common with both; but I do not think that's quite sufficient to remove the concern.) It could be argued that we should hew strictly to the letter of the SQL standard and forbid foreign-key constraints with duplicate referencing columns. Or maybe allow it only if the FK action is not one where we'd run into this problem. I'm not terribly excited about trying to support the case, though. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs