pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: targen@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14124: ON UPDATE CASCADE failure on repeated foreign key column
Date: Mon, 02 May 2016 22:37:20 +0000
Message-ID: <20160502223720.19110.71285@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (3+ messages)  latest in thread

Message-ID: <20160502223720.19110.71285@wrigleys.postgresql.org>
Permalink:  ../20160502223720.19110.71285@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160502223720.19110.71285@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: targen@gmail.com
  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>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox