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

Foreign key constraints allow inconsistent state? #27

Open
jean-lopes opened this issue Jul 8, 2022 · 0 comments
Open

Foreign key constraints allow inconsistent state? #27

jean-lopes opened this issue Jul 8, 2022 · 0 comments

Comments

@jean-lopes
Copy link

Hi, I'm fiddling around with the project and this behavior seems odd to me, can anyone confirm it is the expected outcome?

CREATE TABLE uk (id integer, s integer, e integer, CONSTRAINT uk_pkey PRIMARY KEY (id, s, e));
SELECT periods.add_period('uk', 'p', 's', 'e');
SELECT periods.add_unique_key('uk', ARRAY['id'], 'p', key_name => 'uk_id_p', unique_constraint => 'uk_pkey');

CREATE TABLE fk (id integer, uk_id integer, s integer, e integer, PRIMARY KEY (id));
SELECT periods.add_period('fk', 'q', 's', 'e');
SELECT periods.add_foreign_key('fk', ARRAY['uk_id'], 'q', 'uk_id_p', key_name => 'fk_uk_id_q');

INSERT INTO uk(id, s, e)
    VALUES (1, 1, 3)
         , (1, 3, 5);

INSERT INTO fk(uk_id, id, s, e)
    VALUES (1, 1, 1, 2)
         , (1, 2, 2, 5);

--expected: fail,    behavior: deleted
delete from uk where (id, s, e) = (1, 1 ,3);

--expected: fail,    behavior: failed
delete from uk where (id, s, e) = (1, 3 ,5);

INSERT INTO uk(id, s, e)
    VALUES (2, 1, 5);

INSERT INTO fk(uk_id, id, s, e)
    VALUES (2, 4, 2, 4);

--expected: fail,    behavior: updated
update uk set e = 3 where (id,s,e) = (2,1,5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant