【问题标题】:How to use jsonb_set in jpa repository, for passing dynamic strings?如何在 jpa 存储库中使用 jsonb_set 来传递动态字符串?
【发布时间】:2020-02-29 14:31:07
【问题描述】:

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);

我该怎么办

【问题讨论】:

    标签: java postgresql spring-boot jpa jsonb


    【解决方案1】:

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

    只传递键值。

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-03
      • 2018-09-22
      • 2022-08-12
      • 2013-07-09
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      相关资源
      最近更新 更多