Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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

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
Arrays 通过ScalikeJDBC访问PostgreSQL数组_Arrays_Postgresql_Scala_Data Access Layer_Scalikejdbc - Fatal编程技术网

Arrays 通过ScalikeJDBC访问PostgreSQL数组

Arrays 通过ScalikeJDBC访问PostgreSQL数组,arrays,postgresql,scala,data-access-layer,scalikejdbc,Arrays,Postgresql,Scala,Data Access Layer,Scalikejdbc,我尝试在PostgreSQL 9.4中使用ScalikeJDBC访问数组。DDL: create table itab ( code varchar primary key, group_list varchar[] ); Scala应用程序中定义了一个简单的案例类和加载器 case class Item(code: String, groupSet: List[String]) trait loader { def loadAllItems: List[

我尝试在PostgreSQL 9.4中使用ScalikeJDBC访问数组。DDL:

create table itab (
        code varchar primary key,
        group_list varchar[]
);
Scala应用程序中定义了一个简单的案例类和加载器

case class Item(code: String, groupSet: List[String])

trait loader {
  def loadAllItems: List[Item] = {
      insideReadOnly { implicit session =>
                       sql"select CODE, GROUP_LIST from ITAB"
                       .map(e => Item(
                           e.string("code"),
                           e.array("group_list").asInstanceOf[Buffer[String]]
                        )).list.apply()
                     }
  }
}
运行应用程序时,会出现运行时异常

java.lang.ClassCastException: org.postgresql.jdbc4.Jdbc4Array cannot be cast to scala.collection.mutable.Buffer
我如何解决它? 谢谢Hoviman.

使用
rs.array(“组列表”).getArray.asInstanceOf[array[String]


它只是下面的java.sql.Array

解析。toList工作正常;)


如果您在强制转换之前调用
.getArray()
,它可能会起作用。非常感谢您的回答!现在编译器责备类型不匹配:找到数组[String],但需要列表[String]。当我更改数组[String]上Item.groupSet的类型时,没有任何编译或运行时错误,但我得到的结果是字符串,而不是数组[String]。看起来scalikejdbc将PostgreSQL varchar[]作为简单字符串返回,而不是字符串数组返回。我说得对吗?如果不是,我应该使用字符串插值的隐式转换吗?
e.array("group_list").getArray.asInstanceOf[Array[String]].toList