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

Support CHECK constraints #629

Closed
mpscholten opened this issue Dec 27, 2020 · 2 comments
Closed

Support CHECK constraints #629

mpscholten opened this issue Dec 27, 2020 · 2 comments

Comments

@mpscholten
Copy link
Member

No description provided.

mpscholten added a commit that referenced this issue Dec 27, 2020
Added support for CHECK constraints. Fixes #629
@hendi
Copy link
Collaborator

hendi commented May 17, 2021

This looks like its limited to basic inequality checks. Checks for equality =, NULL testing (IS NULL / IS NOT NULL) and comparisons (> / <) fail. Logic operations are also not supported.

Example that does work in Postgres, but not in IHP:

CREATE TYPE property_type AS ENUM ('haus_buy', 'haus_rent');

CREATE TABLE properties (
    id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
    property_type property_type NOT NULL,
    area_living INT NOT NULL,
    area_garden INT,
    rent_monthly INT DEFAULT NULL,
    price INT DEFAULT NULL
);

ALTER TABLE properties ADD CONSTRAINT foobar CHECK (
    (property_type = 'haus_buy'
        AND area_garden IS NOT NULL 
        AND rent_monthly IS NULL
    )
    OR (property_type = 'haus_rent'
        AND rent_monthly IS NOT NULL
        AND price IS NULL
    )
);

@hendi hendi reopened this May 17, 2021
@mpscholten
Copy link
Member Author

@hendi fixed via 7cbfb1f

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