1

I am trying to create query like:

SELECT *FROM user WHERE name = ANY (VALUES ('Name1'), ('Name2') ...)

Can anyone help me to understand how I can implement it as native @Query in JPA repository?

@Query(value = "SELECT u FROM User u where u.name = ANY **.....**", native = true) 
User findUsersByName(List<String> names);

Now I can't find solution to set names as VALUES ('Name1'), ('Name2')...

Igor S
  • 951
  • 7
  • 19
  • Since you are comparing the values with equals operator `=` I would rather change my SQL to `.. where u.name in :values` then it would be easy to assign a parameter. – mndeveci Jul 05 '18 at 10:08
  • @mndeveci, the variant with VALUES that is described in the question is much more productive. – Igor S Jul 05 '18 at 10:13
  • I understand but can you make it more elaborate, about what is the difference between `IN` and `VALUES` in this case? – mndeveci Jul 05 '18 at 11:15
  • @mndeveci, I am trying to improve IN requests and I found solution with VALUES here https://www.datadoghq.com/blog/100x-faster-postgres-performance-by-changing-1-line/ You can read of request speed improvements in this article in details. After testing request from psql console I saw that values requests mach more faster. Now I am trying to use it in repository, but cant find solution :( – Igor S Jul 05 '18 at 11:27
  • Ohh I understand now. Maybe you can check this discussion; https://stackoverflow.com/questions/36601318/how-to-use-the-postgres-any-clause-with-jpa-hibernate-native-queries-array-para – mndeveci Jul 05 '18 at 11:46

0 Answers0