【发布时间】:2017-06-01 01:31:45
【问题描述】:
我的 postgres 数据库中有一些 JSON,它在一个名为 site_content 的表中,该表有两行,id 和 content,content 是我存储 JSON 的地方。我希望能够根据他的 id 找到一个玩家,我的玩家存储在键 series 下,因为这是从 JSON 创建我的图表所需的键。
这是我目前使用的查询:
Blocking.get {
sql.firstRow("""SELECT * from site_content where content -> 'playersContainer' -> 'series' -> 'id' = ${id} """)
}.map { row ->
log.info("row is: ${row}")
if (row) {
objectMapper.readValue(row.getAt(0).toString(), Player)
}
}
}
但是我得到了这个错误:
org.postgresql.util.PSQLException:错误:运算符不存在: json = 字符变化提示:没有运算符与给定名称匹配 和参数类型。您可能需要添加显式类型转换。
这是我的 JSON 示例:
"id": "${ID}",
"team": {
"id": "123",
"name": "Shire Soldiers"
},
"playersContainer": {
"series": [
{
"id": "1",
"name": "Nick",
"teamName": "Shire Soldiers",
"ratings": [
1,
5,
6,
9
],
"assists": 17,
"manOfTheMatches": 20,
"cleanSheets": 1,
"data": [
3,
2,
3,
5,
6
],
"totalGoals": 19
},
{
"id": "2",
"name": "Pasty",
"teamName": "Shire Soldiers",
"ratings": [
6,
8,
9,
10
],
"assists": 25,
"manOfTheMatches": 32,
"cleanSheets": 2,
"data": [
3,
5,
7,
9,
10
],
"totalGoals": 24
}
]
}
我在这个项目中使用 Groovy,但我想这只是我遇到问题的一般 JSON postgres 语法。
【问题讨论】:
标签: json postgresql groovy