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 · 0 comments


Copy link

commented Aug 20, 2019

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 this to To do in SQL Support via automation Aug 20, 2019

@ndeodhar ndeodhar added this to the v2.0 milestone Aug 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.