在 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 或任何带有空格的东西,那到底是什么?
提前致谢!:-)