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

发布于 2024-11-01 16:01:08 字数 689 浏览 0 评论 0原文

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

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 是一款优秀的数据库软件,我推荐中小型项目使用它。这是我对 SQLite 与 PostgreSQL 的简要比较。

I found this unexpected behavior with SQLite. It appears that SQLite accepts arbitrary keywords in SQL join syntax. If I accidentally type nautral join instead of natural join a cartesian product is produced. Is this the expected behavior, a feature or a bug?

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

Tested with SQLite 3.7.3 on Debian 6.0 and SQLite 3.7.5 on Windows 7.

To add: SQLite is an excellent piece of database software and I recommend it from small to medium size projects. Here is my brief SQLite vs PostgreSQL comparison.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乞讨 2024-11-08 16:01:08

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

nautral and imaginary are parsed as aliases to the table:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文