mirror of
https://github.com/MariaDB/server.git
synced 2026-05-14 02:47:37 +02:00
MDEV-13596 CHECK constraints disallow NULL to pass through, violating SQL
SQL Standard (4.23.3.4 Table check constraints, part 2, SQL:2016) says that CHECK constraint rejects rows *only* if the condition is FALSE. That is, both TRUE and NULL should be allowed.
This commit is contained in:
parent
e6ce97a592
commit
4c6c352138
3 changed files with 23 additions and 1 deletions
|
|
@ -142,3 +142,13 @@ create table t1 (a int check (@b in (select user from mysql.user)));
|
|||
ERROR HY000: Function or expression 'select ...' cannot be used in the CHECK clause of `a`
|
||||
create table t1 (a int check (a > @b));
|
||||
ERROR HY000: Function or expression '@b' cannot be used in the CHECK clause of `a`
|
||||
create table t1 (a int check (a = 1));
|
||||
insert t1 values (1);
|
||||
insert t1 values (2);
|
||||
ERROR 23000: CONSTRAINT `a` failed for `test`.`t1`
|
||||
insert t1 values (NULL);
|
||||
select * from t1;
|
||||
a
|
||||
1
|
||||
NULL
|
||||
drop table t1;
|
||||
|
|
|
|||
|
|
@ -92,3 +92,14 @@ create or replace table t1( c1 int auto_increment primary key, check( c1 > 0 or
|
|||
create table t1 (a int check (@b in (select user from mysql.user)));
|
||||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
|
||||
create table t1 (a int check (a > @b));
|
||||
|
||||
#
|
||||
# MDEV-13596 CHECK constraints disallow NULL to pass through, violating SQL
|
||||
#
|
||||
create table t1 (a int check (a = 1));
|
||||
insert t1 values (1);
|
||||
--error ER_CONSTRAINT_FAILED
|
||||
insert t1 values (2);
|
||||
insert t1 values (NULL);
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
|
|
|||
|
|
@ -5090,7 +5090,8 @@ int TABLE::verify_constraints(bool ignore_failure)
|
|||
{
|
||||
for (Virtual_column_info **chk= check_constraints ; *chk ; chk++)
|
||||
{
|
||||
if ((*chk)->expr->val_int() == 0)
|
||||
/* yes! NULL is ok, see 4.23.3.4 Table check constraints, part 2, SQL:2016 */
|
||||
if ((*chk)->expr->val_int() == 0 && !(*chk)->expr->null_value)
|
||||
{
|
||||
my_error(ER_CONSTRAINT_FAILED,
|
||||
MYF(ignore_failure ? ME_JUST_WARNING : 0), (*chk)->name.str,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue