【发布时间】:2020-03-18 01:14:17
【问题描述】:
我的 postgres 数据库中有一个名为 metadata 的列,它存储一个 JSON 字符串,类型为 TEXT。
我正在尝试运行查询以更新 JSON 中名为 myCount 的字段。我正在使用 Spring Boot 和 JDBC。
String query = "UPDATE " + mTableName + " SET metadata = jsonb_set(metadata::jsonb, '{myCount}', ?)::text" +
" WHERE scope = ?";
PreparedStatement preparedStmt = jdbcTemplate.getDataSource().getConnection().prepareStatement(query);
preparedStmt.setInt (1, myCount);
preparedStmt.setString(2, scope);
// execute the java preparedstatement
return preparedStmt.executeUpdate();
我收到以下错误:ERROR: function jsonb_set(jsonb, unknown, integer) does not
知道如何运行更新 JSON 中的 myCount 列的查询吗?
【问题讨论】:
-
@a_horse_with_no_name 仍然存在问题 - `错误:函数 jsonb_set(jsonb, text[], integer) 不存在`,关于 jsonb,因为内存数据库不支持测试中的 json
-
“因为内存数据库不支持测试中的 json”,这意味着您将永远无法测试您是否在数据库中存储了有效的 JSON。我也很确定这个内存数据库也不支持
jsonb_set(),那么你将如何测试这段代码? -
@a_horse_with_no_name 9.5.9
-
@a_horse_with_no_name 让我们专注于这个问题,当列为
json(function jsonb_set(jsonb, text[], integer) does not exist) 时我有同样的错误
标签: java postgresql jdbc