简体   繁体   English

在python中执行snowflake SQL语句时snowflake-python错误

[英]snowflake-python error while executing snowflake SQL statement in python

I get this error why i try to execute a dynamic sql just built while executing the program我收到此错误,为什么我在执行程序时尝试执行刚刚构建的动态 sql

'SnowflakeCursor' object has no attribute 'strip' 'SnowflakeCursor' 对象没有属性 'strip'

This is the dynamic SQL这是动态SQL

Alter_add_dyn_sql="SELECT 'ALTER TABLE "+schema+"."+object_name+" ADD(COL_Y VARCHAR2(100));' FROM DUAL;"

Here is the call to execute the cursor i have opened这是执行我打开的游标的调用

This is the dynamic SQL这是动态SQL

 cs_dev_cdw=dev_cdw_conn.cursor()
 print(Alter_add_dyn_sql)                         
 Alt_add_sql=cs_dev_cdw.execute(Alter_add_dyn_sql)
 print(Alt_add_sql)

   output: Alter_add_dyn_sql="SELECT 'ALTER TABLE "+schema+"."+object_name+" ADD(COL_Y 
    VARCHAR2(100));' FROM DUAL;"
 Alt_add_sql=cs_dev_cdw.execute(Alter_add_dyn_sql)
 execute error:
 'SnowflakeCursor' object has no attribute 'strip'

dev_cdw_conn definition dev_cdw_conn 定义

dev_cdw_conn = sf.connect (dev_cdw_database=config.dev_cdw_database,dev_warehouse=config.dev_warehouse,user=config.username,password=config.password,account=config.account,dev_role=config.dev_cdw_role)

I wasn't able to reproduce your error, but I do see one problem in your code: you don't have to construct the SQL statement by selecting from dual.我无法重现您的错误,但我确实在您的代码中看到了一个问题:您不必通过从双中选择来构建 SQL 语句。 You can just pass in the SQL statement as a string:您可以将 SQL 语句作为字符串传入:

Alter_add_dyn_sql='ALTER TABLE '+schema+'.'+object_name+' ADD(COL_Y VARCHAR2(100));'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM