数组包含到 postgres jsonb 和 Spring 数据 JDBC

问题描述

我们去旅行吧...

我想要达到的是

SELECT * FROM people WHERE interest->'interests' ?| ARRAY['sport','cars'];

进入我的存储库定义为

public interface PeopleRepository extends CrudRepository<People,UUID> {
   @Query("SELECT * FROM people where interest->'interests' ??| :array::text[] ")
   List<People> findByInterest(@Param("array") String interest);

最后选择兴趣,用这种方式

findByInterest("{foo,beer}") 

这是我经过一天的测试和 恕我直言真的MEH

我认为最好的解决方案是可能的 (在运行时没有 sql 强制转换和字符串连接)

你能帮忙提供一个更“干净的代码”的解决方案吗? (抱歉,帖子太长了)

更新

我会更好地阐述我的问题。 我正在寻找类似的东西

@Query("SELECT * FROM people where interest->'interests' ??| :array::text[] ")
List<People> findByInterest(@Param("array") List<String> interest);

这可能吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)