我试图在Server中运行Python,并希望定义一个包含简单select查询结果的变量。
exec sp_execute_external_script
@language = N'python', @script = N'
import pandas as pd
inventory = pd.DataFrame(sql_inventory)
',
@input_data_1 = N'SELECT top 10 * from inventory',
@input_data_1_name = N'sql_inventory'SQL server表(库存)的结构如下:
ProductID numeric(18,3)
RegionID numeric(18,3)
ShopCode int
QTY float
Date varchar(6)
Amount float
ID bigint但是我得到了以下错误:在使用HRESULT0x80004004执行'sp_execute_external_script‘时发生了一个'Python’脚本错误。Msg 39019,级别16,状态2,第1行发生外部脚本错误:
列“ProductID”中不支持的输入数据类型。受支持的类型: bit、tinyint、smallint、int、bigint、unique标识符、real、float、char、varchar、nchar、nvarchar、varbinary。SqlSatelliteCall错误:列“ProductID”中不支持的输入数据类型。受支持的类型: bit、tinyint、smallint、int、bigint、unique标识符、real、float、char、varchar、nchar、nvarchar、varbinary。来自外部脚本的STDOUT消息(S):SqlSatelliteCall函数失败。有关更多信息,请参见控制台输出。回溯(最近一次调用):文件"C:\Program \Microsoft Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\computecontext\RxInSqlServer.py",行406,在rx_sql_satellite_call rx_native_call("SqlSatelliteCall",params)文件"C:\Program \Microsoft Server\MSSQL14.MSSQLSERVER\PYTHON_SERVICES\lib\site-packages\revoscalepy\RxSerializable.py",第291行中,rx_native_call ret = px_call(functionname,params) RuntimeError: revoscalepy函数失败。
应该在每次从查询中读取数据时指定数据类型吗?
发布于 2019-12-17 17:22:12
这个微软文章非常清楚地解释了正在发生的事情,并且错误消息也相当清楚。
归根结底,Python不支持Numeric或Decimal数据类型,也不支持其他Server数据类型,如DateTime或任何地理位置数据项。因此,要处理这些数据类型,您必须使用不同的技术。
这个StackOverflow项目有一些关于使用熊猫来处理这个过程的好信息,还有一些其他的项目。
https://dba.stackexchange.com/questions/255773
复制相似问题