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 jdbc,pgobject可用类型,数组类型_Postgresql_Scala_Jdbc_Scalikejdbc - Fatal编程技术网

postgresql jdbc,pgobject可用类型,数组类型

postgresql jdbc,pgobject可用类型,数组类型,postgresql,scala,jdbc,scalikejdbc,Postgresql,Scala,Jdbc,Scalikejdbc,我将postgresql 9.5与jdbc驱动程序9.4.1208.jre7和scalikejdbc包装一起使用 我的桌子是: CREATE TABLE refs ( name character varying NOT NULL, custom json, prices integer[] ) 我可以使用org.postgresql.util.PGobject插入json值: val res = new PGobject() res.setType("json") res.set

我将postgresql 9.5与jdbc驱动程序9.4.1208.jre7和scalikejdbc包装一起使用

我的桌子是:

CREATE TABLE refs
(
  name character varying NOT NULL,
  custom json,
  prices integer[]
)
我可以使用org.postgresql.util.PGobject插入json值:

val res = new PGobject()
res.setType("json")
res.setValue("{'name': 'test'}")
res
我还想插入数组。我该怎么做?我认为这会起作用:

  def toArrStr(a: Iterable[String]): PGobject = {
    val res = new PGobject()
    res.setType("ARRAY")
    res.setValue(s"{${a.map(i => '"' + i + '"').mkString(",")}}")
    res
  }
但它给了我一个异常:
org.postgresql.util.PSQLException:Unknown-type-ARRAY

也许我缺少smth,但我找不到关于PGObject类的好文档。我认为PGObject类的设计目的和我的完全一样,但它的行为并不像预期的那样


POSTGRES有很多类型,不仅仅是数组,还有日期、日期时间、日期范围、时间范围等等。我相信它对应的类型应该有类型名。

我理解了如何使用PGObject保存字符列表[]:

  def toArrStr(a: Iterable[String]): PGobject = {
    val res = new PGobject()
    res.setType("varchar[]")
    res.setValue(s"{${a.map(i => '"' + i + '"').mkString(",")}}")
    res
  }
要保存数字数组,请执行以下操作: 其中大小为2,4,8(smallint、int、bigint)


可能与某些注释重复:可能应该使用类似Java的接口类,而不是内部PostgreSQL实现。第二:posgresqljdbc的内部
javadoc
。第三:PostgreSQL对
JSON
-有很好的本机支持。marcospereira,您提供的答案没有使用PGobjectzloster,首先:我想使用内部PostgreSQL实现,因为编写“{”my“,”str“,”array“}”然后使用java类型要简单得多,尝试从scala类型转换到java只是为了更新列。第二:谢谢链接。第三:我已经知道postgres有本地json支持,那么你有什么建议?忘记数组本机类型并在json/jsonb字段中保留任何数据?第四:我不是唯一一个使用PGObject的人,看看
  def toArrNum(a: Iterable[AnyVal], size: Int): PGobject = {
    val res = new PGobject()
    res.setType(s"int$size[]")
    res.setValue(s"{${a.mkString(",")}}")
    res
  }