英文:
My query runs in terminal but giving syntax error inside a Javascript procedure
问题
我有一个在终端中运行正常的查询。但是当我将它添加到JavaScript Snowflake存储过程中时,它给我报错。
查询:
SELECT replace('[[:space:]]+('||listagg(keyword, '|')||')[[:space:]]+', '\\', '\\\\') as pattern FROM qwerty;
错误信息:
SQL编译错误:
语法错误,位于第1行第79个位置,意外的 '\\\\'。
解析错误,位于第3行第8个位置,附近是 '<EOF>'。
我做错了什么?
英文:
I have a query that runs fine when ran in terminal. But when I add it in a javascript snowflake procedure, its giving me an error.
The query:
SELECT replace('[[:space:]]+('||listagg(keyword, '|')||')[[:space:]]+', '\\', '\\\\') as pattern FROM qwerty;
The error:
SQL compilation error:
syntax error line 1 at position 79 unexpected '\\'.
parse error line 3 at position 8 near '<EOF>'.
What am I doing wrong
答案1
得分: 1
JavaScript转义反斜杠。Snowflake也是如此。这意味着当您在Snowflake中的JavaScript存储过程中放置反斜杠时,您需要双重转义它们。请尝试以下操作:
SELECT replace('[[:space:]]+('||
listagg(keyword, '|')||')
[[:space:]]+', '\\', '\\\\') as pattern FROM qwerty;
英文:
JavaScript escapes backslashes. So does Snowflake. This means that when you put backslashes in a JavaScript SP in Snowflake, you need to double escape them. Try this:
SELECT replace('[[:space:]]+('||listagg(keyword, '|')||')
[[:space:]]+', '\\\\', '\\\\\\\\') as pattern FROM qwerty;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论