Skip to content
Advertisement

PostgreSQL query works on pgAdmin but not in Spring Boot

The query SELECT * FROM books WHERE (isbn || ' ' || author || ' ' || name) ILIKE '%el%' returns

output

from the full db when executed in pgAdmin (PostgreSQL tool)

full-db

But the same query doesn’t seem to work when I try to run it in Spring Boot, it returns an empty list. I do not know if my query is PostgreSQL specific or if it’s native SQL, if it isn’t native SQL then I guess it is reasonable that it does not work seeing as I have nativeQuery = true which if I have understood things correctly means that native SQL is expected. Without it, the application does not even run. If the case is as described, how do I specify that I want to use PostgreSQL in the query?

BookController.java

JavaScript

BookService.java

JavaScript

BookRepository.java

JavaScript

Books.html the value I am entering is el.

JavaScript

Advertisement

Answer

The parameter ? may not be applied properly in the query. Change '%?%' to '%' || ? || '%' as in:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement