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

The explicit NULL column constraint is not working in Citus 12 #7110

Closed
pbav opened this issue Aug 11, 2023 · 2 comments
Closed

The explicit NULL column constraint is not working in Citus 12 #7110

pbav opened this issue Aug 11, 2023 · 2 comments

Comments

@pbav
Copy link

pbav commented Aug 11, 2023

ALTER TABLE a ADD COLUMN b INT NULL;
[2023-08-11 11:53:30] [XX000] ERROR: unsupported constraint type
[2023-08-11 11:53:30] Detail: constraint type: 0

Citus 12.0.0 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3), 64-bit
PostgreSQL 15.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit

It worked on Citus 11.2.1:
Citus 11.2.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3), 64-bit
PostgreSQL 15.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit

The NOT NULL constraint works on both versions.
Code like this, with the explicit NULL clause, is generated by Django.

@pbav
Copy link
Author

pbav commented Aug 11, 2023

Workaround - create a custom database backend:

# db_backend/base.py
from django_multitenant.backends.postgresql.base import DatabaseWrapper as CitusDatabaseWrapper, TenantDatabaseFeatures

class DatabaseFeatures(TenantDatabaseFeatures):
    # The explicit NULL constraint (ALTER TABLE a ADD COLUMN b INT NULL) is broken in Citus 12
    implied_column_null = True

class DatabaseWrapper(CitusDatabaseWrapper):
    features_class = DatabaseFeatures
# your_project/settings.py
DATABASES = {
    'default': {
        'ENGINE': 'your_project.db_backend',
        ...
    }
}

@JelteF
Copy link
Contributor

JelteF commented Aug 11, 2023

I'm pretty sure that is fixed by this PR: #7093

It will be part of the next patch release.

@JelteF JelteF closed this as completed Aug 11, 2023
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

2 participants