[英]Snowflake case when statement not working using args
I am trying to make the select statement dependent on an args variable I am passing via a python script (in this case args.type='hello').我试图使 select 语句依赖于我通过 python 脚本传递的 args 变量(在本例中为 args.type='hello')。
It looks like this:它看起来像这样:
case when '{{type}}' = 'hello'
then
SELECT
name from table1
else
SELECT
city from table2 where code='usa'
end
The error I am getting:我得到的错误:
syntax error unexpected 'case'.
syntax error unexpected 'else'.
syntax error unexpected ')'.
I also tried IFF clause but did run into same issues.我也试过 IFF 条款但确实遇到了同样的问题。
If you were sending this sql to snowflake and it was failing due to a syntax error, I would expect you to get an error like "SQL compilation error: ...".如果您将此 sql 发送到 snowflake 并且由于语法错误而失败,我希望您会收到类似“SQL 编译错误:...”的错误。 Therefore I wonder if the issue isn't in your python program.
因此,我想知道问题是否出在您的 python 程序中。
Could you share more?你能分享更多吗?
Where you trying to set some paramters?你在哪里尝试设置一些参数? The snowflake python connector supports several syntaxes:
雪花 python 连接器支持多种语法:
format: .execute("... WHERE my_column = %s", (value,))
pyformat: .execute("... WHERE my_column = %(name)s", {"name": value})
qmark: .execute("... WHERE my_column = ?", (value,))
numeric: .execute("... WHERE my_column = :1", (value,))
If you are using python3 you can use something like f" {pythonvar} ".如果您使用的是 python3,则可以使用 f" {pythonvar} " 之类的东西。 Could you give us more context about what you are doing?
你能给我们更多关于你在做什么的背景吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.