在Spring Boot应用程序中,我有一个在postgresql服务器上执行的SQL查询,如下所示:
@Query(value = "select count(*) from servers where brand= coalesce(?1, brand) " +
"and flavour= coalesce(?2, flavour) ; ",
nativeQuery = true)
Integer icecreamStockCount(String country, String category);
然而,
执行方法时出现以下错误:
ERROR: COALESCE types bytea and character varying in PostgreSQL
如何将String value = null传递给查询?
**注意:**我发现我的问题与JPA Query to handle NULL parameter value不同
你不需要合并,试试这个
@Query("select count(*) from servers where (brand = ?1 or ?1 is null)" +
" and (flavour = ?2 or ?2 is null)")
Integer icecreamStockCount(String country, String category);
在Hibernate 5.0.2之前不允许使用null参数。请参阅https://hibernate.atlassian.net/browse/HHH-9165以及对https://www.postgresql.org/message-id/[email protected]的回复