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

CHECK constraints #115

Open
federico-razzoli opened this issue Mar 1, 2019 · 6 comments
Open

CHECK constraints #115

federico-razzoli opened this issue Mar 1, 2019 · 6 comments
Projects

Comments

@federico-razzoli
Copy link

CREATE TABLE t (
    birth_date INT,
    death_date INT,
    [ CONSTRAINT chk_a_b ] CHECK (birth_date < death_date OR death_date IS NULL)
);

The CONSTRAINT part is optional and is useful only to specify a name. Names are useful because they appear in error messages.

@FCO
Copy link
Owner

FCO commented Mar 1, 2019

::?CLASS.^add-constraint-check: { .birth-date < .death-date OR not .death-date.defined };

Or

::?CLASS.^add-constraint-check: chk_a_b, { .birth-date < .death-date OR not .death-date.defined };

Sent with GitHawk

@FCO
Copy link
Owner

FCO commented Mar 1, 2019

Should it warn when using a driver of database that do not support CHECK

Sent with GitHawk

@jonathanstowe
Copy link
Contributor

I was going to write "or. like SQLite, accept the check definition but don't actually do the check" only to discover that it actually does, which was somewhat of a pleasant surprise.

@FCO
Copy link
Owner

FCO commented Mar 2, 2019

SQLite do use it? I’m surprised! :)

Sent with GitHawk

@jonathanstowe
Copy link
Contributor

Apparently https://www.sqlite.org/lang_createtable.html I'm of the habit of just assuming that for most things it will accept the definition but just not do anything with it.

@federico-razzoli
Copy link
Author

No actually it works as it should in SQLite. In MySQL prior to 8.0 and in MariaDB prior to 10.3 (or something like that) the CHECKs are not enforced.

@FCO FCO added this to To do in Red via automation Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Red
  
To do
Development

No branches or pull requests

3 participants