Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.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 使用Set[Int]参数的光滑编译查询_Postgresql_Scala_Prepared Statement_Slick_Slick 3.0 - Fatal编程技术网

Postgresql 使用Set[Int]参数的光滑编译查询

Postgresql 使用Set[Int]参数的光滑编译查询,postgresql,scala,prepared-statement,slick,slick-3.0,Postgresql,Scala,Prepared Statement,Slick,Slick 3.0,我有一个以Seq[Int]为参数的查询(并执行类似WHERE x IN(…)的过滤),我需要编译它,因为这个查询非常复杂。然而,当我尝试天真的方法时: Compiled((xs: Set[Int]) => someQuery.filter(_.x inSet xs)) 它失败的消息是 Computation of type Set[Int] => Query[SomeTable, SomeValue, Seq] cannot be compiled (as type C) Sli

我有一个以
Seq[Int]
为参数的查询(并执行类似
WHERE x IN(…)
的过滤),我需要编译它,因为这个查询非常复杂。然而,当我尝试天真的方法时:

Compiled((xs: Set[Int]) => someQuery.filter(_.x inSet xs))
它失败的消息是

Computation of type Set[Int] => Query[SomeTable, SomeValue, Seq] cannot be compiled (as type C)
Slick可以编译以一组整数作为参数的查询吗


更新:我使用PostgreSQL作为数据库,因此可以在子句中使用数组而不是
,但是如何使用呢?

至于PostgreSQL数据库,解决方案比我预期的要简单得多

首先,对于支持阵列的PostgreSQL,需要一个特殊的光滑驱动程序。它通常已经包含在依赖PgSQL特性的项目中,所以根本没有问题。我用

其主要思想是替换(…)
子句中的普通SQL
,该子句使用与列表中的项目数量相同的绑定参数数量,因此不能由Slick使用PgSQL特定的数组运算符
x=ANY(arr)
静态编译,该运算符只为数组使用一个参数。使用这样的代码很容易:

val compiledQuery = Compiled((x: Rep[List[Int]]) => query.filter(_.id === x.any))
这段代码将生成类似于
的查询,其中x=ANY(?)
将只使用一个参数,所以Slick将接受它进行编译