sqlite3 3.5.7 与 3.6.21 括号问题
我正在编写一个执行 sqlite3 查询的 python (2.7) 脚本。我正在 Windows 计算机上测试这个查询,它的工作方式就像一个魅力。当我打开 Linux 时,查询失败。它给出了一个错误:它找不到这样的列...(即tableA.ID显然存在并且没有拼写错误)
该查询基本上是创建平面表的左连接序列。
它的格式是:
select tableA.fieldA,tableA.fieldB, tableB.fieldC etc...
from ((tableA LEFT JOIN tableB on tableA.ID = tableB.FID) LEFT JOIN tableC on tableA.ID = tableC.FID) etc...
这种查询在 Windows 上有效,但在 Linux 上失败并出现该错误,除非我像这样删除 Linux 上的括号:
select tableA.fieldA,tableA.fieldB, tableB.fieldC etc...
from tableA LEFT JOIN tableB on tableA.ID = tableB.FID LEFT JOIN tableC on tableA.ID = tableC.FID etc...
在这种情况下,它不会给出错误并执行查询。 现在,除了操作系统之外,两个系统之间唯一的不同之处是:
(from python)
>>>import sqlite3
>>>sqlite3.sqlite_version
'3.5.7' (this is on linux)
>>>sqlite3.sqlite_version
'3.6.21' (this is on windows)
这两个版本之间有什么不同,以及如何使代码在 Linux 上工作(可能使用括号)? 很难判断不带括号的查询结果是否可信以及是否与带括号的查询结果相同,因为它的数据量很大,需要长时间的测试才能确保一切正常。
编辑:没有括号的 LEFT JOIN 如何工作?将首先加入左侧的大多数表,然后加入其余的?如果我确定查询在没有括号的情况下也会以相同的方式运行,我可以这样做。我将左连接从最左到最右分组,即: (((((AB)C)D)E)F)
I am writing a python (2.7) script which executes a sqlite3 query. I am testing this query on a windows computer and it works like a charm. When I switch on Linux the query fails. it gives an error: it cannot find such a column... (i.e. tableA.ID wich exists obviously and it has no typos)
The query is basically a sequence of left join that creates a flat table.
It is in the format:
select tableA.fieldA,tableA.fieldB, tableB.fieldC etc...
from ((tableA LEFT JOIN tableB on tableA.ID = tableB.FID) LEFT JOIN tableC on tableA.ID = tableC.FID) etc...
this kind of query works on windows but fails on linux with that error unless I remove the brackets on linux like this:
select tableA.fieldA,tableA.fieldB, tableB.fieldC etc...
from tableA LEFT JOIN tableB on tableA.ID = tableB.FID LEFT JOIN tableC on tableA.ID = tableC.FID etc...
in this case it does not give the error and executes the query.
now the only different thing between the two systems beside the operating system is:
(from python)
>>>import sqlite3
>>>sqlite3.sqlite_version
'3.5.7' (this is on linux)
>>>sqlite3.sqlite_version
'3.6.21' (this is on windows)
what is different between those two versions and how can i make the code work on linux (using parenthesis possibly)?
it's very hard to tell if the result of the query without brackets can be trusted and whether it is the same as the one with, since it's a huge amount of data and would require long tests before making sure everything is ok.
EDIT: how does a LEFT JOIN works without brackets? will be first joined left most tables and then the rest? if I am sure the query would behave the same way without brakets I can go for it. i am grouping left joins from left most to rightmost, i.e.: (((((A B)C)D)E)F)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议首先在两个平台上协调 sqlite3,以便 Linux 和 Windows 运行相同的版本。截至撰写本文时(2012 年 4 月 30 日),当前版本为 3.7.11。 为 http://www.sqlite.org/download.html
下载地址 我发现从 Linux 发行版存储库获得的代码版本通常已经过时,因此最好直接从软件的网站下载。
I would recommend first harmonizing your sqlite3's on the two platforms so Linux and Windows are running the same version. As of this writing (April 30, 2012) the current version is 3.7.11. Downloads are available at http://www.sqlite.org/download.html
As a side note I find that the versions of code you get from the Linux distro's repository generally tend to be out of date so it is better to download from the software's web site directly.