可空列的行为不如此
Nullable column not behaving as such
我有一个 table actor
和一个可为空的列 first_name
。我将特定行设置为空:
update actor set first_name=null where actor_id=201;
Query OK, 1 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
然后我尝试使用我的 where 子句中的空值查询 table,但没有得到任何回复:
select * from actor where first_name is null;
Empty set (0.00 sec)
但是如果我 select 检查该列是否为空字符串,我会得到正确的值:
select * from actor where first_name = '';
[...]
1 row in set (0.00 sec)
存储引擎是MyISAM。为什么空列被设置为空字符串?
更新
我看到了 1 个警告,但是 mysql CLI 没有显示任何警告。我怎样才能做到这一点?
还有:
desc actor;
+-------------+----------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------------------+------+-----+-------------------+-----------------------------+
| actor_id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| first_name | varchar(45) | NO | | NULL | |
| last_name | varchar(45) | NO | MUL | NULL | |
| last_update | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+----------------------+------+-----+-------------------+-----------------------------+
根据 Table 的描述,看起来包括 first_name 在内的所有列都不为空。您确定它是可为空的列吗?
我有一个 table actor
和一个可为空的列 first_name
。我将特定行设置为空:
update actor set first_name=null where actor_id=201;
Query OK, 1 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
然后我尝试使用我的 where 子句中的空值查询 table,但没有得到任何回复:
select * from actor where first_name is null;
Empty set (0.00 sec)
但是如果我 select 检查该列是否为空字符串,我会得到正确的值:
select * from actor where first_name = '';
[...]
1 row in set (0.00 sec)
存储引擎是MyISAM。为什么空列被设置为空字符串?
更新
我看到了 1 个警告,但是 mysql CLI 没有显示任何警告。我怎样才能做到这一点?
还有:
desc actor;
+-------------+----------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------------------+------+-----+-------------------+-----------------------------+
| actor_id | smallint(5) unsigned | NO | PRI | NULL | auto_increment |
| first_name | varchar(45) | NO | | NULL | |
| last_name | varchar(45) | NO | MUL | NULL | |
| last_update | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-------------+----------------------+------+-----+-------------------+-----------------------------+
根据 Table 的描述,看起来包括 first_name 在内的所有列都不为空。您确定它是可为空的列吗?