【发布时间】:2026-02-05 19:45:02
【问题描述】:
我昨天遇到了这个问题,同时尝试使用我在 Azure ML 的“应用 SQL 转换”模块中使用的相同 sqlite 脚本,在 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 的一个关键特性,运行递归代码的能力是任何函数式语言(如 Sqlite)的“必备”。
我还尝试在 Azure 的 Jupyter Notebook 中运行我的 Python 脚本,它也按预期工作。
我们在 Python 模块中的 Sqlite 配置是否可能与在 Jupyter Notebook 和“应用 SQL 转换”模块中的配置不同?
【问题讨论】:
-
便宜的答案是尝试添加您想要的特定版本的 sqllite3,这是一个指南。 blogs.msdn.com/b/andreasderuiter/archive/2015/02/16/… 但我实际上也没有在该列表中看到 sqllite3 ......很可能笔记本和模块包版本不同步。
标签: python sqlite common-table-expression azure-machine-learning-studio cortana-intelligence