Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Incorrect ON UPDATE CASCADE Behaviour with Multiple References #2111

srhickma opened this issue Aug 20, 2019 · 1 comment
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue


Copy link

srhickma commented Aug 20, 2019

Jira Link: DB-2510
If a table contains multiple columns referencing the same column of another table, one of which uses ON UPDATE CASCADE, updating the referenced value will cause an error.

For example:

SET default_transaction_isolation = 'SERIALIZABLE';

CREATE TABLE test_table(id int UNIQUE, pk int PRIMARY KEY);

CREATE TABLE ref_table(
    id int,
    ref1 int REFERENCES test_table(id),
    ref2 int REFERENCES test_table(id) ON UPDATE CASCADE

INSERT INTO test_table(id, pk) VALUES (1, 1);
INSERT INTO ref_table(ref2) VALUES (1);

UPDATE test_table SET id = 2 WHERE pk = 1;

Produces the following error:

ERROR:  insert or update on table "ref_table" violates foreign key constraint "ref_table_ref2_fkey"
DETAIL:  Key (ref2)=(0) is not present in table "test_table".

In this case it is expected that the value of 1 in the ref_table.ref2 column would be updated to 2, without error.

NOTE: This issue goes away if the order of ref1 and ref2 in the ref_table creation statement are reversed.

@srhickma srhickma added kind/bug This issue is a bug area/ysql Yugabyte SQL (YSQL) labels Aug 20, 2019
@srhickma srhickma added this to To do in YSQL via automation Aug 20, 2019
@ndeodhar ndeodhar added this to the v2.0 milestone Aug 28, 2019
@ndeodhar ndeodhar added the priority/high High Priority label Aug 28, 2019
@ndeodhar ndeodhar removed the priority/high High Priority label Apr 28, 2020
Copy link

Note: This works with snapshot isolation but fails in serializable mode.

@ndeodhar ndeodhar modified the milestones: v2.0, v2.2 May 13, 2020
@ndeodhar ndeodhar modified the milestones: v2.2, v2.2.x Jun 8, 2020
@ndeodhar ndeodhar moved this from To do to Backlog in YSQL Aug 5, 2020
@yugabyte-ci yugabyte-ci added the priority/medium Medium priority issue label Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
area/ysql Yugabyte SQL (YSQL) kind/bug This issue is a bug priority/medium Medium priority issue
Status: No status

No branches or pull requests

4 participants