Given a table as follows:
MariaDB [test]> create table ck_test (
|
-> x int,
|
-> CHECK (x IN (0, 1))
|
-> );
|
Query OK, 0 rows affected (0.06 sec)
|
|
the database disallows the value of "x" to be NULL:
MariaDB [test]> insert into ck_test (x) values (NULL);
|
ERROR 4025 (23000): CONSTRAINT `CONSTRAINT_1` failed for `test`.`ck_test`
|
|
This despite the fact that the constraint condition here evaluates to NULL:
MariaDB [test]> SELECT NULL IN (0, 1);
|
+----------------+
|
| NULL IN (0, 1) |
|
+----------------+
|
| NULL |
|
+----------------+
|
1 row in set (0.38 sec)
|
|
|
|
Per SQL standard in Foundations:
"4.6.6.3 Table constraints"
"A table check constraint specifies a search condition. The constraint is violated if the result of the search condition is false for any row of the table (but not if it is unknown)."
the result here is NULL, not false; null is "unknown".
The behavior is also inconsistent with that of other major databases:
Postgresql:
psql (9.5.7)
|
Type "help" for help.
|
|
test=# CREATE TABLE ck_test(
|
test(# x int,
|
test(# CHECK (x IN (0, 1))
|
test(# );
|
CREATE TABLE
|
test=# insert into ck_test (x) values (NULL);
|
INSERT 0 1
|
|
|
|
Oracle:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
|
|
SQL> CREATE TABLE ck_test (
|
x int,
|
CHECK (x IN (0, 1))
|
)
|
2 3 4 5 ;
|
|
Table created.
|
|
SQL> insert into ck_test (x) values (NULL);
|
|
1 row created.
|
|
- relates to
-
MDEV-7563
Support CHECK constraint as in (or close to) SQL Standard
-
-
Closed
{"report":{"fcp":1964.5999999046326,"ttfb":864.3999998569489,"pageVisibility":"visible","entityId":62779,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"36074611-cce6-487c-9b44-89138c7efe93","navigationType":0,"readyForUser":2051.5,"redirectCount":0,"resourceLoadedEnd":2615,"resourceLoadedStart":870.1999998092651,"resourceTiming":[{"duration":572.6000001430511,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":870.1999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":870.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1442.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":572.6999998092651,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":870.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":870.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1443.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":628.3000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":870.6999998092651,"connectEnd":870.6999998092651,"connectStart":870.6999998092651,"domainLookupEnd":870.6999998092651,"domainLookupStart":870.6999998092651,"fetchStart":870.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":870.6999998092651,"responseEnd":1499,"responseStart":1499,"secureConnectionStart":870.6999998092651},{"duration":688.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":870.8999998569489,"connectEnd":870.8999998569489,"connectStart":870.8999998569489,"domainLookupEnd":870.8999998569489,"domainLookupStart":870.8999998569489,"fetchStart":870.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":870.8999998569489,"responseEnd":1559.0999999046326,"responseStart":1559.0999999046326,"secureConnectionStart":870.8999998569489},{"duration":691.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":871.1999998092651,"connectEnd":871.1999998092651,"connectStart":871.1999998092651,"domainLookupEnd":871.1999998092651,"domainLookupStart":871.1999998092651,"fetchStart":871.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":871.1999998092651,"responseEnd":1563,"responseStart":1563,"secureConnectionStart":871.1999998092651},{"duration":692.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":871.2999999523163,"connectEnd":871.2999999523163,"connectStart":871.2999999523163,"domainLookupEnd":871.2999999523163,"domainLookupStart":871.2999999523163,"fetchStart":871.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":871.2999999523163,"responseEnd":1563.3999998569489,"responseStart":1563.3999998569489,"secureConnectionStart":871.2999999523163},{"duration":692.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":871.5,"connectEnd":871.5,"connectStart":871.5,"domainLookupEnd":871.5,"domainLookupStart":871.5,"fetchStart":871.5,"redirectEnd":0,"redirectStart":0,"requestStart":871.5,"responseEnd":1563.7999999523163,"responseStart":1563.7999999523163,"secureConnectionStart":871.5},{"duration":772.6000001430511,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":871.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":871.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1644.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":692.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":871.7999999523163,"connectEnd":871.7999999523163,"connectStart":871.7999999523163,"domainLookupEnd":871.7999999523163,"domainLookupStart":871.7999999523163,"fetchStart":871.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":871.7999999523163,"responseEnd":1564.2999999523163,"responseStart":1564.2999999523163,"secureConnectionStart":871.7999999523163},{"duration":772.2000000476837,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":872.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":872.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1644.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":692.6000001430511,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":872.1999998092651,"connectEnd":872.1999998092651,"connectStart":872.1999998092651,"domainLookupEnd":872.1999998092651,"domainLookupStart":872.1999998092651,"fetchStart":872.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":872.1999998092651,"responseEnd":1564.7999999523163,"responseStart":1564.7999999523163,"secureConnectionStart":872.1999998092651},{"duration":1595.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":873.0999999046326,"connectEnd":873.0999999046326,"connectStart":873.0999999046326,"domainLookupEnd":873.0999999046326,"domainLookupStart":873.0999999046326,"fetchStart":873.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":873.0999999046326,"responseEnd":2468.5,"responseStart":2468.5,"secureConnectionStart":873.0999999046326},{"duration":1741.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":873.1999998092651,"connectEnd":873.1999998092651,"connectStart":873.1999998092651,"domainLookupEnd":873.1999998092651,"domainLookupStart":873.1999998092651,"fetchStart":873.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":873.1999998092651,"responseEnd":2615,"responseStart":2615,"secureConnectionStart":873.1999998092651},{"duration":811.7000000476837,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1657.1999998092651,"connectEnd":1657.1999998092651,"connectStart":1657.1999998092651,"domainLookupEnd":1657.1999998092651,"domainLookupStart":1657.1999998092651,"fetchStart":1657.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":1657.1999998092651,"responseEnd":2468.899999856949,"responseStart":2468.899999856949,"secureConnectionStart":1657.1999998092651},{"duration":677.7999999523163,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1958,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1958,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2635.7999999523163,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":703,"responseStart":864,"responseEnd":868,"domLoading":868,"domInteractive":2642,"domContentLoadedEventStart":2642,"domContentLoadedEventEnd":2692,"domComplete":4181,"loadEventStart":4181,"loadEventEnd":4183,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2620.199999809265},{"name":"bigPipe.sidebar-id.end","time":2621.399999856949},{"name":"bigPipe.activity-panel-pipe-id.start","time":2621.699999809265},{"name":"bigPipe.activity-panel-pipe-id.end","time":2625.0999999046326},{"name":"activityTabFullyLoaded","time":2700.5}],"measures":[],"correlationId":"77086a6cd91948","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":96,"dbReadsTimeInMs":10,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}