1

在 sqlite3 中,我使用以下语法将行插入到表中:

INSERT INTO schedule VALUES(some_date, (SELECT id_from_another_table WHERE where_clause));

显而易见的假设是,这个嵌入式 (SELECT ...) 查询在其结果集为空时将返回 NULL。

然而,情况似乎并非如此……

sqlite> .schema schedule
CREATE TABLE schedule(date date, agent_id integer);

sqlite> select * from schedule;
2014-01-09|22
2014-01-09|
2014-01-09|23
2014-01-09|24

请注意第二行如何缺少 agent_id 条目?

sqlite> select * from schedule where agent_id = null;
#nothing

sqlite> select * from schedule where agent_id = 0;
#nothing

sqlite> select * from schedule where agent_id = "";
#nothing

sqlite> select * from schedule where agent_id LIKE "% %";
#nothing

如果那个 agent_id 不匹配 null、""、0 或任何带有空格的东西,那到底是什么?

提前致谢!:-)

4

1 回答 1

2

在我使用过的所有其他数据库中,语法是column IS NULL. 据我所知,在 sqlite 中是一样的。

select * from schedule where agent_id IS NULL;
于 2014-01-05T21:53:16.873 回答