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,我想動態(tài)插入該值..但它給出了錯誤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);我應(yīng)該怎么辦
2 回答

慕運維8079593
TA貢獻1876條經(jīng)驗 獲得超5個贊
添加演員陣容'{business,key)} AS TEXT[]'
例子
@Query(value = "Update onboarding.onboarding_cases set case_data=jsonb_set(case_data,CAST('{business,key)}' AS TEXT[]),to_jsonb(?1)) where case_id=?2", nativeQuery = true)
void updateColumn(String toAdd, BigInteger case_id);

墨色風雨
TA貢獻1853條經(jīng)驗 獲得超6個贊
終于解決了這個問題。為那些尋找的人發(fā)布答案。
只傳遞鍵值。
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);
添加回答
舉報
0/150
提交
取消