SQLite接受SQL语法中不存在的连接类型

时间:2011-04-14 10:26:23

标签: sql sqlite syntax join cartesian-product

我在SQLite中发现了这种意外行为。似乎SQLite在SQL连接语法中接受任意关键字。如果我不小心输入中立连接而不是自然连接,则会生成笛卡尔积。这是预期的行为,功能还是错误?

select count(*) from pri; -- 22
select count(*) from sec; -- 57458

select count(*) from pri natural join sec; -- 57458 
select count(*) from pri nautral join sec; -- 1264076
select count(*) from pri advanced natural join sec; -- 57458
select count(*) from pri imaginary join sec; -- 1264076

在Debian 6.0上使用SQLite 3.7.3和在Windows 7上使用SQLite 3.7.5进行测试。

要添加:SQLite是一个很好的数据库软件,我推荐它从中小型项目。这是my brief SQLite vs PostgreSQL comparison.

1 个答案:

答案 0 :(得分:2)

nautralimaginary被解析为表的别名:

select count(*) from (pri) natural join sec; -- 57458 
select count(*) from (pri AS nautral) join sec; -- 1264076
select count(*) from (pri AS advanced) natural join sec; -- 57458
select count(*) from (pri AS imaginary) join sec; -- 1264076