未能使用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)

它以错误CCD_ 1失败。

我不相信这个错误与绑定参数有任何关系,因为不创建表的简单select语句会顺利工作:

s = text("""select * from dual where 1 = :a """)
con.execute(s, a = 1).fetchall()
#[('X',)]

在"创建表"one_answers"绑定参数"中似乎有某种东西破坏了查询。知道为什么会发生这种情况以及如何解决吗?

DDL语句中不允许使用绑定变量。这就是为什么它能像预期的那样在简单查询中工作,但一旦有了createtable语句,它就会失败。不幸的是,您将不得不在没有任何绑定变量的情况下编写DDL语句!

最新更新