1

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)

4

1 回答 1

0

我建议首先在两个平台上协调您的 sqlite3,以便 Linux 和 Windows 运行相同的版本。截至撰写本文时(2012 年 4 月 30 日),当前版本为 3.7.11。下载地址为http://www.sqlite.org/download.html

附带说明一下,我发现您从 Linux 发行版存储库获得的代码版本通常会过时,因此最好直接从该软件的网站下载。

于 2012-04-30T16:22:07.970 回答