Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python panda.to_sql通过mysql.connector调用带参数的存储过程_Python_Mysql_Pandas_Read Sql - Fatal编程技术网

Python panda.to_sql通过mysql.connector调用带参数的存储过程

Python panda.to_sql通过mysql.connector调用带参数的存储过程,python,mysql,pandas,read-sql,Python,Mysql,Pandas,Read Sql,我有一些Connection类,它有\u enter\u和\u退出方法返回mysql.connector.MySQLConnection实例 所需的是运行mysql存储过程并将数据作为数据帧获取。 我已经尝试了很多方法使用:?,%s,:1,%(name)s并将list、tuple和dict传递到参数中 with Connection(**self._connection) as conn: df = pandas.read_sql("call stored_procedure (?);",

我有一些Connection类,它有\u enter\u和\u退出方法返回mysql.connector.MySQLConnection实例

所需的是运行mysql存储过程并将数据作为数据帧获取。 我已经尝试了很多方法使用:?,%s,:1,%(name)s并将list、tuple和dict传递到参数中

with Connection(**self._connection) as conn:
   df = pandas.read_sql("call stored_procedure (?);", conn, params=['test'])
我读了,还有一些其他人,仍然找不到解决方案,因为它总是失败,因为“SQL语句中没有使用所有参数”,或者要求使用Multi=True


当然,我们可以使用游标读取数据,获取数据并将其传递到DataFrame构造函数中,但根据文档,必须有一种使用pandas.read\u sql的方法。

摘要:您不能使用参数以这种方式调用SP
证明:

您调用存储的proc,但需要实际选择数据,select语句在哪里?您想说无法通过read_sql调用SP吗?我假设proc返回一个结果集。SQL中是否还有其他返回行/值的语句重新仔细阅读,我停下来说:SQL:string SQL query或SQLAlchemy Selective(select或text object),这可能意味着您无法在read\u SQL中调用sp。存储过程不是表或数据样本,而是您执行的一系列SQL语句,您需要的是过程的输出,某种类型的dim/fact/stage/temp表。你需要选择那个。