使用args语句不工作时的雪花情况

2024-04-19 11:15:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使select语句依赖于通过python脚本传递的args变量(在本例中为args.type='hello')

看起来是这样的:

  case when '{{type}}' = 'hello'
  then
        SELECT
        name from table1
  else
        SELECT
        city from table2 where code='usa'
  end

我得到的错误是:

syntax error unexpected 'case'.
syntax error unexpected 'else'.
syntax error unexpected ')'.

我也尝试了IFF子句,但确实遇到了同样的问题


Tags: from脚本hellotypeargserror语句select
2条回答

如果您将此sql发送到snowflake,但由于语法错误而失败,我希望您会收到类似“sql编译错误:…”这样的错误。因此,我想知道这个问题是否不在python程序中

你能分享更多吗

你想在哪里设置一些参数? snowflake 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,))

如果您使用的是python3,那么可以使用类似于f“{pythonvar}”的东西。 你能给我们更多关于你正在做什么的背景吗

相关问题 更多 >