英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论