EXECUTE IMMEDIATE在BigQuery中与INSERT一起使用时不起作用。

huangapple go评论66阅读模式
英文:

EXECUTE IMMEDIATE not working with INSERT in bigquery

问题

我试图运行以下代码:

EXECUTE IMMEDIATE "INSERT INTO `bombora_surge.company_intent_history` (RowKey,?) VALUES ('sample',?)" USING "1",2;

但我不断收到以下错误:

无效的 EXECUTE IMMEDIATE SQL 字符串 `INSERT INTO `bombora_surge.company_intent_history` (RowKey,?) VALUES ('sample',?)`,语法错误:在 [1:19] 处意外的 "?"

我该如何解决这个问题?

英文:

I am trying to run this following code:

EXECUTE IMMEDIATE "INSERT INTO `bombora_surge.company_intent_history` (RowKey,?) VALUES ('sample',?)" USING "1",2;

But I am continuously getting the following error:

Invalid EXECUTE IMMEDIATE sql string `INSERT INTO `bombora_surge.company_intent_history` (RowKey,?) VALUES ('sample',?)`, Syntax error: Unexpected "?" at [1:19]

How do I resolve this?

答案1

得分: 1

将此内容发布为维基,以提高社区的可见性:

正如@Jaytiger建议的那样,您可以使用反引号(`)来表示问号符号,因为它会将其识别为列名,而不是用于执行 immediate 的占位符。

如果您想将1用作列名,需要使用反引号将? 包围起来,如(RowKey, ?)。

良好的参考链接:

https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#execute_immediate

英文:

Posting this as a wiki for a better visibility for the community:

as @Jaytiger suggests you can use back-quote for the question mark symbol as it will recognise it as a column name and not as a place holder for execute immediate.

> you need to back-quote the ? like (RowKey, ?) if you want to use 1 as a column name.

Good reference:

https://cloud.google.com/bigquery/docs/reference/standard-sql/procedural-language#execute_immediate

huangapple
  • 本文由 发表于 2023年6月16日 03:45:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485067.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定