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

sql: Foreign Key Cannot Reference Its Own Row #27871

Closed
xudongzheng opened this issue Jul 24, 2018 · 5 comments
Closed

sql: Foreign Key Cannot Reference Its Own Row #27871

xudongzheng opened this issue Jul 24, 2018 · 5 comments
Assignees
Labels
A-sql-fks A-sql-mutations Mutation statements: UPDATE/INSERT/UPSERT/DELETE. A-sql-pgcompat Semantic compatibility with PostgreSQL C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.

Comments

@xudongzheng
Copy link
Contributor

xudongzheng commented Jul 24, 2018

  • What did you do?
create table example (a text references example (b), b text unique);
insert into example values ('a', 'a');
  • What did you expect to see?

The query works in postgresql

  • What did you see instead?
pq: foreign key violation: value ['a'] not found in example@example_b_key [b]

This type of structure can be helpful for storing a rooted tree where the root is defined as pointing to itself. Using NULL for the parent of the root prevents me from making (a, b) a composite primary key.

@knz knz changed the title Foreign Key Cannot Reference Its Own Row sql: Foreign Key Cannot Reference Its Own Row Jul 30, 2018
@knz knz added C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. A-sql-mutations Mutation statements: UPDATE/INSERT/UPSERT/DELETE. labels Jul 30, 2018
@knz knz added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Jul 30, 2018
@knz
Copy link
Contributor

knz commented Jul 30, 2018

cc @BramGruneir @emsal1863

@jordanlewis
Copy link
Member

This should be fixed by the upcoming refresh of FKs by the optimizer in 19.2.

@rafiss
Copy link
Collaborator

rafiss commented Dec 4, 2019

This also relates to #20041

@knz
Copy link
Contributor

knz commented Dec 4, 2019

Solution is described (and will be implemented by fixing) #33475.

@RaduBerinde
Copy link
Member

Opt-driven FK checks are enabled on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-fks A-sql-mutations Mutation statements: UPDATE/INSERT/UPSERT/DELETE. A-sql-pgcompat Semantic compatibility with PostgreSQL C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
Projects
None yet
Development

No branches or pull requests

6 participants