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 keys in between reference tables are not supported #2378

Closed
handuy opened this issue Sep 11, 2018 · 4 comments
Closed

Foreign keys in between reference tables are not supported #2378

handuy opened this issue Sep 11, 2018 · 4 comments

Comments

@handuy
Copy link

handuy commented Sep 11, 2018

I have 2 tables
Users:
CREATE TABLE users (id int PRIMARY KEY, name text);
Posts:
CREATE TABLE posts (id int PRIMARY KEY, author_id int REFERENCES users(id));

Let's load some sample data:
INSERT INTO users VALUES (1, 'Duy'), (2, 'Long'), (3, 'Huy');
INSERT INTO posts VALUES (1, 2), (2, 2), (3, 3);

When I create reference tables for the 2 tables:
SELECT create_reference_table('users');
SELECT create_reference_table('posts');

I have an error message:
ERROR: cannot create foreign key constraint because reference tables are not supported as the referencing table of a foreign constraint
DETAIL: Reference tables are only supported as the referenced table of a foreign key when the referencing table is a hash distributed table

Does that mean citus do not support foreign key constraints between reference tables ?

@furkansahin
Copy link
Contributor

Hey @handuy ,
Yes, currently Citus supports foreign keys in two cases;

  1. From hash distributed tables to hash distributed tables when the foreign key includes the distribution column,
  2. From hash distributed tables to reference tables on any column.

@furkansahin furkansahin changed the title Foreign key for reference tables Foreign keys in between reference tables are not supported Sep 12, 2018
@gfontenay
Copy link

gfontenay commented Jan 17, 2019

We have a couple of dozen tables that would qualify as reference tables and the lack of FKs between them is a showstopper in considering migration to Citus Cloud. This involves genomic data and there are a lot of critical relationships for which we want and need PG enforcement.

@pykello pykello self-assigned this Jul 10, 2019
@prevostc
Copy link

prevostc commented Sep 3, 2019

+1, this is quite a big limitation that is not even cited in the documentation. As a general conclusion, it is not possible to use citus in an existing codebase without a significant schema rewrite (at the time of writing)

@marcocitus
Copy link
Member

marcocitus commented Sep 3, 2019

Fixed by a5b087c will be part of the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants