简体   繁体   English

当语句无法使用 args 时的雪花案例

[英]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.

相关问题 使用* args时参数传递 - Argument passing when using *args 在 pyspark 中使用带有 case when 语句的 isin 时出错 - getting error while using isin with case when statement in pyspark 如果使用随机数时语句不起作用 - If statement not working when using random numbers 如何在 python 的返回中添加 if 和 else 条件? 类似于在 SQL 中的 Case 语句中使用 case when - How to add if and else condition within a return in python? Similar to using case when within a Case statement in SQL 使用字符串时如何使用 *args - how do I use *args when working with a string 在 Databricks 中使用 SQL 的语句时,如何在单个案例中创建多个“ELSE”语句? - How to create multiple 'ELSE' statements in a single case when statement using SQL in Databricks? 当我使用时间戳字符串时,cql 查询语句不起作用 - cql query statement is not working when i using timestamp string 使用雪花连接器和 COPY INTO 功能将 csv 上传到雪花时如何指定分隔符 - how to specify delimiter when uploading csv onto snowflake using snowflake connector & COPY INTO function 在Python中使用Dictionaries代替Case / Switch语句 - Using Dictionaries in Python in place of Case/Switch statement 如何使用python编写case语句 - how to write case statement using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM