我昨天遇到了这个问题,同时尝试使用我在"应用SQL转换"中使用的相同sqlite脚本。 Azure ML中的模块,Azure ML中的Sqlite over Python模块:
with tbl as (select * from t1)
select * from tbl
这是我得到的错误:
[Critical] Error: Error 0085: The following error occurred during script evaluation, please view the output log for more information:
---------- Start of error message from Python interpreter ----------
File "C:\server\invokepy.py", line 169, in batch
data:text/plain,Caught exception while executing function: Traceback (most recent call last):
odfs = mod.azureml_main(*idfs)
File "C:\pyhome\lib\site-packages\pandas\io\sql.py", line 388, in read_sql
File "C:\temp\azuremod.py", line 193, in azureml_main
results = pd.read_sql(query,con)
coerce_float=coerce_float, parse_dates=parse_dates)
File "C:\pyhome\lib\site-packages\pandas\io\sql.py", line 1017, in execute
File "C:\pyhome\lib\site-packages\pandas\io\sql.py", line 1022, in read_sql
cursor = self.execute(*args)
raise_with_traceback(ex)
File "C:\pyhome\lib\site-packages\pandas\io\sql.py", line 1006, in execute
---------- End of error message from Python interpreter ----------
cur.execute(*args)
DatabaseError: Execution failed on sql: with tbl as (select * from t1)
select * from tbl
和Python代码:
def azureml_main(dataframe1 = None, dataframe2 = None):
import pandas as pd
import sqlite3 as lite
import sys
con = lite.connect('data1.db')
con.text_factory = str
with con:
cur = con.cursor()
if (dataframe1 is not None):
cur.execute("DROP TABLE IF EXISTS t1")
dataframe1.to_sql('t1',con)
query = '''with tbl as (select * from t1)
select * from tbl'''
results = pd.read_sql(query,con)
return results,
用以下代码替换查询时
select * from t1
它按预期工作。 正如您可能知道的那样,公用表表达式是Sqlite中的一个关键特性,运行递归代码的能力是“必须具备的”#34;在任何功能语言中,例如Sqlite。
我还尝试在Azure中的Jupyter Notebook中运行我的Python脚本,该脚本也按预期工作。
我们是否有可能在Python模块中为Sqlite配置不同于Jupyter Notebook和"应用SQL转换"模块?
答案 0 :(得分:2)
我转发了您的问题,并在http://pandas.pydata.org/pandas-docs/stable/io.html#sql-queries审核了SQL Queries
pandas.io.sql
的{{1}}文档。我尝试使用read_sql_query
来解决它,但失败了。
根据pandas
doc,似乎Pandas
不支持此SQL语法的用法。
根据我的经验并根据您的SQL,我尝试使用SQL select * from (select * from t1) as tbl
而不是适用于Pandas
的SQL。
希望它有所帮助。最好的祝福。