I wrote a Postgres query as below and it is failing at build. How to implement it in Spring-boot Hibernate?
@Query(value="SELECT t from CatalogView t WHERE t.locations=:locations AND STRING_TO_ARRAY(t.myColumn, ',') @> STRING_TO_ARRAY(:myColumn, ',')")
public Set<TrainerGuides> getData(@Param("locations") String locations,@Param("myColumn") String myColumn);
Why i wrote this? to compare a bunch of strings separated by coma with unorder string input in Postgres.
catalog
----------------------------------
id title keywords
----------------------------------
1 Title-1 k2,k1,k3,k4,k5
2 Title-2 k1,k3,k5,k6
To select the rows by comparing keywords with my input k1,k2,k5
In this above example, row with id: 1 has to come.
SELECT *
FROM catalog
WHERE STRING_TO_ARRAY(keywords, ',') @> STRING_TO_ARRAY('k1,k2,k5', ',')
@Queryindicate a native query? You won't be able to use DBMS specific functions and operators in HQL or JPQL