BUG #14124: ON UPDATE CASCADE failure on repeated foreign key column

From: targen(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #14124: ON UPDATE CASCADE failure on repeated foreign key column
Date: 2016-05-02 22:37:20
Message-ID: 20160502223720.19110.71285@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 14124
Logged by: Manuel Gómez
Email address: targen(at)gmail(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2016-05-02 23:39:52 Re: BUG #14124: ON UPDATE CASCADE failure on repeated foreign key column
Previous Message Andres Freund 2016-05-02 22:14:19 Re: [BUGS] Breakage with VACUUM ANALYSE + partitions