[英]Failing to create table using bound parameters in sqlalchemy/cx_oracle
我想使用绑定参数在数据库中执行“创建表”语句。 这有效(没有绑定参数):
from sqlalchemy.sql import text
from sqlalchemy import create_engine
con = create_engine(\\..)
s = text("""create table test_table as select * from dual where 1 = 1 """)
con.execute(s)
但是,如果我使用绑定参数:
s = text("""create table test_table as select * from dual where 1 = :a """)
con.execute(s, a = 1)
它失败,并显示错误DatabaseError: (cx_Oracle.DatabaseError) ORA-01036: illegal variable name/number
。
我不认为此错误与绑定参数有任何关系,因为没有表创建的简单select语句会顺利运行:
s = text("""select * from dual where 1 = :a """)
con.execute(s, a = 1).fetchall()
#[('X',)]
在“创建表”和“绑定参数”中似乎有些东西破坏了查询。 知道为什么会这样以及如何解决吗?
DDL语句中不允许绑定变量。 这就是为什么它可以通过简单查询按预期运行的原因,但是一旦有了create table语句,它就会失败。 不幸的是,您将必须编写没有任何绑定变量的DDL语句!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.