Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 在用于嵌入式文本查询的Anorm prepared查询中,未替换参数_Postgresql_Scala_Anorm - Fatal编程技术网

Postgresql 在用于嵌入式文本查询的Anorm prepared查询中,未替换参数

Postgresql 在用于嵌入式文本查询的Anorm prepared查询中,未替换参数,postgresql,scala,anorm,Postgresql,Scala,Anorm,我们有一个用例,需要将查询的结果集透视到insert语句的列。为此,我们使用了交叉表,它将文本sql作为参数 因此,查询在概念上可能如下所示: insert into table(col1, col2, ...) select col1, col2, ... from crosstab($$ select .... where something = {something} $$) ... 在postgresql客户机中,这一切都非常好 现在,当我们试图用Anorm在代码中实现这一点时

我们有一个用例,需要将查询的结果集透视到insert语句的列。为此,我们使用了
交叉表
,它将文本sql作为参数

因此,查询在概念上可能如下所示:

insert into table(col1, col2, ...)
select col1, col2, ...
from crosstab($$
  select ....
  where something = {something}
$$)
...
在postgresql客户机中,这一切都非常好

现在,当我们试图用Anorm在代码中实现这一点时,它将如下所示:

val sql = $"""
|insert into table(col1, col2, ...)
|select col1, col2, ...
|from crosstab($$$$
|  select ....
|  where something = {something}
|$$$$)
|...
"""

SQL(sql).on("something" -> param).execute()
这应该行得通,但行不通。原因是在这种特殊情况下,内部SQL字符串中定义的参数不会被实际值替换

当然,可以使用字符串插值手工构建SQL字符串。但是,我更愿意使用为其构建的工具


在这种情况下,有什么方法可以使参数替换工作正常?

这不应该是
val sql=s”““..${something}…”“
?@mfirry正如我所提到的,我试图避免手动替换查询,而是使用anorm API代替1。而是使用Anorm插值。2.避免使用
$$$
作为分隔符。我明白了。因此,
$”…
来自Anorm?@cchantep对于交叉表,我必须使用自定义delimeter。我更愿意使用Anorm插值,但在这种情况下它不起作用:)