java - 如何在jpa存储库中使用jsonb_set来传递动态字符串?

标签 java postgresql spring-boot jpa jsonb

postgres 命令在 pgadmin4 中有效,但在 java 代码中无效

    String toAdd = "case_data->'business' || '{\"l\":\"cpaz\"}'";
this.orchestrateRepo.updateColumn(toAdd, case_id);



 @Query(value = "Update onboarding.onboarding_cases set case_data = jsonb_set(case_data, '{business}', ?1 )where case_id=?2", nativeQuery = true)
        void updateColumn(String toAdd, BigInteger case_id);

我正在向Add传递一个字符串,我想动态插入该值..但它给出了错误

org.postgresql.util.PSQLException: ERROR: function jsonb_set(jsonb, unknown, character varying) does not exist
  Hint: No function matches the given name and argument types. You might need to add explicit type casts.

如果我这样写,查询就可以正常工作

 @Query(value = "Update onboarding.onboarding_cases set case_data = jsonb_set(case_data, '{business}', case_data->'business' || '{"t":"cpaz"}' )where case_id=?2", nativeQuery = true)
        void updateColumn(BigInteger case_id);

我该怎么办

最佳答案

终于解决这个问题了。为那些寻找答案的人发布答案。

仅传递键值。

String toAdd = "value";

将查询更改为:

@Query(value = "Update onboarding.onboarding_cases set case_data=jsonb_set(case_data,'{business,key)}',to_jsonb(?1)) where case_id=?2", nativeQuery = true)
    void updateColumn(String toAdd, BigInteger case_id);

关于java - 如何在jpa存储库中使用jsonb_set来传递动态字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58690639/

相关文章:

java - 为什么 InputStreamReader 在从 jar 读取时抛出 NPE?

java - 与枚举类型混淆

sql - 在限定时间内获得 COUNT() 结果

sql - PostgreSQL 中的全文搜索与模糊搜索相结合

java - 分段阅读_第 403 章

java - FileChannel.force 和 FileDescriptor.sync 都需要吗?

postgresql - 为什么 SQL drop 语句会超时

maven - 找不到 SpringApplicationConfiguration : Erroneous spring-boot-starter-test content?

java - Spring Boot 与 Hibernate : Keep Creating Database when already Exist

java - 不打印到文本框