我的查询在终端中运行,但在JavaScript过程内部出现语法错误。

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

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(&#39;[[:space:]]+(&#39;||listagg(keyword, &#39;|&#39;)||&#39;)[[:space:]]+&#39;, &#39;\\&#39;, &#39;\\\\&#39;) as pattern FROM qwerty;

The error:
SQL compilation error:
syntax error line 1 at position 79 unexpected &#39;\\&#39;.
parse error line 3 at position 8 near &#39;&lt;EOF&gt;&#39;.

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(&#39;[[:space:]]+(&#39;||listagg(keyword, &#39;|&#39;)||&#39;)
[[:space:]]+&#39;, &#39;\\\\&#39;, &#39;\\\\\\\\&#39;) as pattern FROM qwerty;

huangapple
  • 本文由 发表于 2023年7月14日 00:21:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681500.html
匿名

发表评论

匿名网友

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

确定