【问题标题】:Unable to call stored procedures using sqlalchemy?无法使用 sqlalchemy 调用存储过程?
【发布时间】:2021-08-13 18:14:06
【问题描述】:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc('transfer', [1, 2, 1000])# fetch result parameters
results = list(cursor.fetchall())
cursor.close()
connection.commit()
connection.close()

我收到此错误:

Traceback(最近一次调用最后一次): 文件“D:\z_data\PYTHON\oops\sql_statements.py”,第 66 行,在 cursor.callproc('传输',[1,2,1000]) psycopg2.errors.WrongObjectType: transfer(integer, integer, integer) 是一个过程 第 1 行:SELECT * FROM transfer(1,2,1000) ^ 提示:要调用过程,请使用 CALL。

[0.4s完成]

【问题讨论】:

  • 我不太确定您的错误。可以试试connection.execute('transfer ?, ?, ?', [1,2,1000]) 吗?
  • 不,它不工作
  • 试试connection.execute('CALL transfer (?, ?, ?)', [1,2,1000])
  • 它的工作......非常感谢你

标签: python postgresql sqlalchemy psycopg2


【解决方案1】:

来自

https://www.psycopg.org/docs/cursor.html#cursor.callproc

注意:callproc() 只能与 PostgreSQL 函数 一起使用,不能与 PostgreSQL 11 中引入的 procedures 一起使用,后者需要运行 CALL 语句。请使用普通的execute() 运行它们。

【讨论】:

  • 感谢您的解释......它与执行一起工作
猜你喜欢
  • 2018-01-10
  • 1970-01-01
  • 2016-01-23
  • 2011-04-03
  • 2020-01-24
  • 1970-01-01
  • 2020-11-12
  • 2019-12-07
相关资源
最近更新 更多