From: | PG Bug reporting form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Cc: | marcus(at)cockroachlabs(dot)com |
Subject: | BUG #17261: FK ON UPDATE CASCADE can break referential integrity with columns of different types |
Date: | 2021-11-01 21:09:00 |
Message-ID: | 17261-b27dbaa13eba2220@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: 17261
Logged by: Marcus Gartner
Email address: marcus(at)cockroachlabs(dot)com
PostgreSQL version: 14.0
Operating system: macOS Big Sur 11.6
Description:
It is possible to break foreign key referential integrity when the FK
columns have different types and updates are cascaded from the parent
relation to the child relation. As far as I can tell from the documentation
on FKs
(https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-FK)
this behavior is not expected. The example below shows how to reproduce the
issue.
This behavior is present on 14.0 and 13.3. I did not test any other
versions.
-- To reproduce:
CREATE TABLE p (d DECIMAL(10, 2) PRIMARY KEY);
CREATE TABLE c (d DECIMAL(10, 0) REFERENCES p(d) ON UPDATE CASCADE);
INSERT INTO p VALUES (1.00);
INSERT INTO c VALUES (1);
-- Update the parent row value to 1.45.
UPDATE p SET d = 1.45 WHERE d = 1.00;
SELECT * FROM p;
-- d
-- ------
-- 1.45
-- The FK constraint integrity is not upheld.
-- I would expect the update to have failed, because 1 (the
-- value of the assignment cast from 1.45 to DECIMAL(10, 0))
-- does not exist in p.
SELECT * FROM c;
-- d
-- ---
-- 1
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2021-11-01 21:59:49 | Re: BUG #17261: FK ON UPDATE CASCADE can break referential integrity with columns of different types |
Previous Message | Matthias van de Meent | 2021-11-01 15:15:27 | Re: BUG #17257: (auto)vacuum hangs within lazy_scan_prune() |