我正在使用Scala/Play框架构建调查应用程序,并使用Postgres9.4和Anorm。我在其他地方使用JSONB作为数据类型,但在一个位置上,我想使用JSONB[],认为这种类型是JSONB值的数组。我的JSON结构如下:
[
{"guitar":{"passion":3,
"expertise":5,
"willingToTeach":false,
"lookingForOthers":false
}
},
{"soccer":{"passion":3,
"expertise":3,
"willingToTeach":true,
"lookingForOthers":true
}
}
]
这里每个兴趣都是一个json结构。我已经能够使用jsonb
作为数据类型将json响应值添加到pgsql的其他列中,但当我尝试使用jsonb[]
时,就会出现错误信息:[PSQLException: Unknown type jsonb[].]
在pgadmin3中,它确实显示了我正在尝试插入的列的确切数据类型:jsonb[]
。在我的anorm插入代码中,我尝试设置类型:
val pgObject = new PGobject();
pgObject.setType("jsonb")
但是我收到了这个错误:
[PSQLException: ERROR: column "passions" is of type jsonb[] but expression is of type jsonb
Hint: You will need to rewrite or cast the expression.
Position: 43]
我尝试查找,但是似乎找不到可以作为pgObject.setType()参数的所有字符串值。我也不确定如何将表达式从jsonb
转换为jsonb[]
,除了使用setType()方法设置类型之外,是否还有其他方法。
非常感谢任何帮助。
jsonb[]
?jsonb
内部有本地数组格式。使用 PostgreSQL 的jsonb
值数组没有意义。 - Craig Ringer