雪花变种数据插入问题:'专家级问题'
我有一个雪花上的桌子,桌子的结构如下所示。
数据 | ID | TIMESTAMP |
---|---|---|
变体类型 | VARCHAR | VARCHAR |
I正在将此数据插入表中
let data = {
"a":"hi",
"b":"i'm the problem"
}
let id = "id";
let timestamp = "2022-06-29 20:30:44"
let data1 = JSON.stringify(data);
let data2 = data1.replace(/\'/g, "\\'");
我的插入查询是
`插入XYZ(数据,ID,TIMESTAMP)选择Parse_json('$ {data}'),'$ {id}'),'$ {id}','$ {timestamp}'`
当我运行查询时,它会出现错误。 SQL汇编错误:位置378意外'\“ \ nsyntax错误第2行2”,
没有单个报价的记录插入正确的记录。但是带有一个报价值的数据字段如上所述。尝试了很多事情。 请建议。
I have a table in snowflake and the structure of the table is like below.
Data | id | timestamp |
---|---|---|
variant type | varchar | varchar |
I am inserting this data into the table
let data = {
"a":"hi",
"b":"i'm the problem"
}
let id = "id";
let timestamp = "2022-06-29 20:30:44"
let data1 = JSON.stringify(data);
let data2 = data1.replace(/\'/g, "\\'");
my insert query is
` insert into xyz (Data,id,timestamp) select parse_json('${data}'),'${id}','${timestamp}' `
when I am running the query it is giving an error.
SQL compilation error:\nsyntax error line 2 at position 378 unexpected ''\"
the record which doesn't have a single quote is inserted properly. but the data field with a single quote value is giving the error as mentioned above. I have tried many things.
please suggest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此JavaScript助手功能将逃脱一个字符串,以用作插入语句中的单引号。它仅在因某种原因无法使用绑定变量的情况下使用。
您可以更改此行:
对此:
将辅助功能添加到SP或Node.js代码中,这将起作用。
This Javascript helper function will escape a string to use as a single-quoted literal in an insert statement. It should only be used in situations where bind variables cannot be used for some reason.
You can change this line:
To this:
With the helper function added to the SP or Node.js code, this will work.
由于我们没有看到整个过程,因此我根据您的问题创建了一个过程:
如您所见,我使用了$ {data2},并且有效:
As we don't see the whole procedure, I created one based on your question:
As you see, I used ${data2}, and it worked: