How do I use spring data jpa to query jsonb column?

后端 未结 5 1979
小蘑菇
小蘑菇 2020-12-29 12:11

I\'m having a problem getting this native query right against a postgres 9.4 instance.

My repository has a method:

 @Query(value = \"SELECT t.* \" +
         


        
5条回答
  •  余生分开走
    2020-12-29 12:57

    If the operator is being converted to a question mark for one reason or another, then you should try using the function instead. You can find the corresponding function using \doS+ #>> in the psql console. It tells us the function called is jsonb_extract_path_text. This would make your query:

    @Query(value = "SELECT t.* " +
            "FROM my_table t " +
            "WHERE t.field_1 = ?1 " +
            "AND t.field_2 = 1 " +
            "AND t.field_3 IN ?2 " +
            "AND jsonb_extract_path_text(t.jsonb_field, '{key,subkey}') = ?3",
            nativeQuery = true)
    

提交回复
热议问题