org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record
org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record
@Query(value = "SELECT DISTINCT * " +
"FROM chores WHERE id in (SELECT a.id " +
"FROM chores as a INNER JOIN chores_assign_users as b ON a.id=b.chore_id " +
"WHERE (a.is_deleted=FALSE " +
"AND a.family_id=:familyId " +
"AND (:userId IS NULL OR (cast(b.user_id as VARCHAR) IN :userId)) " +
"AND (:status IS NULL OR (a.status IN :status)) " +
"AND (:title IS NULL OR a.title LIKE cast(:title as text)) " +
"AND (:from IS NULL OR :to IS NULL OR cast(created_at as VARCHAR) >= :from AND cast(created_at as VARCHAR) <= :to)) " +
"ORDER BY :sortByDeadline" +
", CASE WHEN :sortByDeadline THEN a.deadline END DESC " +
", CASE WHEN NOT :sortByDeadline THEN a.created_at END DESC)",
countQuery = "SELECT COUNT(DISTINCT a.id) FROM chores as a INNER JOIN chores_assign_users as b ON a.id=b.chore_id " +
"WHERE a.is_deleted=FALSE " +
"AND a.family_id=:familyId " +
"AND (:userId IS NULL OR (cast(b.user_id as VARCHAR) IN (:userId))) " +
"AND (:status IS NULL OR (a.status IN (:status))) " +
"AND (:title IS NULL OR a.title LIKE cast(:title as text))" +
"AND (:from IS NULL OR :to IS NULL OR cast(created_at as VARCHAR) >= :from AND cast(created_at as VARCHAR) <= :to)) ",
nativeQuery = true)
ArrayList<Chore> findAlLFilteredByUserAndStatusAndTitleSortedByCreatedAtOrDeadLine(@Param("familyId") int familyId,
@Param("userId") List<String> userId,
@Param("status") List<String> status,
@Param("title") String title,
@Param("sortByDeadline") boolean sortByDeadline,
@Param("from") String from,
@Param("to") String to,
Pageable pageable);
我在 jpa 存储库中有这个本机查询。如您所见,我搜索具有 user_id IN :userId
的记录。只要 userId
只包含一个元素,这就可以正常工作。但是如果userId
包含多个元素,就会抛出这个异常org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record
。同样的问题发生在"AND (:status IS NULL OR (a.status IN :status)) "
user_id
类型为整数
status
类型为 varchar
我很难找到解决此问题的方法。你能帮我解决这个问题吗?而且,通过将每个元素转换为字符串,将整数列表作为字符串列表传递给查询是否很好,就像我在这种情况下对 userId
所做的那样?这可能是问题所在吗?我该如何解决?感谢您的宝贵时间!
org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record.
The same problem happens to "AND (:status IS NULL OR (a.status IN :status)) "
我认为使用 COALESCE(:status) IS NULL
而不是 :status IS NULL
可以解决上述问题。
@Query(value = "SELECT DISTINCT * " +
"FROM chores WHERE id in (SELECT a.id " +
"FROM chores as a INNER JOIN chores_assign_users as b ON a.id=b.chore_id " +
"WHERE (a.is_deleted=FALSE " +
"AND a.family_id=:familyId " +
"AND (:userId IS NULL OR (cast(b.user_id as VARCHAR) IN :userId)) " +
"AND (:status IS NULL OR (a.status IN :status)) " +
"AND (:title IS NULL OR a.title LIKE cast(:title as text)) " +
"AND (:from IS NULL OR :to IS NULL OR cast(created_at as VARCHAR) >= :from AND cast(created_at as VARCHAR) <= :to)) " +
"ORDER BY :sortByDeadline" +
", CASE WHEN :sortByDeadline THEN a.deadline END DESC " +
", CASE WHEN NOT :sortByDeadline THEN a.created_at END DESC)",
countQuery = "SELECT COUNT(DISTINCT a.id) FROM chores as a INNER JOIN chores_assign_users as b ON a.id=b.chore_id " +
"WHERE a.is_deleted=FALSE " +
"AND a.family_id=:familyId " +
"AND (:userId IS NULL OR (cast(b.user_id as VARCHAR) IN (:userId))) " +
"AND (:status IS NULL OR (a.status IN (:status))) " +
"AND (:title IS NULL OR a.title LIKE cast(:title as text))" +
"AND (:from IS NULL OR :to IS NULL OR cast(created_at as VARCHAR) >= :from AND cast(created_at as VARCHAR) <= :to)) ",
nativeQuery = true)
ArrayList<Chore> findAlLFilteredByUserAndStatusAndTitleSortedByCreatedAtOrDeadLine(@Param("familyId") int familyId,
@Param("userId") List<String> userId,
@Param("status") List<String> status,
@Param("title") String title,
@Param("sortByDeadline") boolean sortByDeadline,
@Param("from") String from,
@Param("to") String to,
Pageable pageable);
我在 jpa 存储库中有这个本机查询。如您所见,我搜索具有 user_id IN :userId
的记录。只要 userId
只包含一个元素,这就可以正常工作。但是如果userId
包含多个元素,就会抛出这个异常org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record
。同样的问题发生在"AND (:status IS NULL OR (a.status IN :status)) "
user_id
类型为整数
status
类型为 varchar
我很难找到解决此问题的方法。你能帮我解决这个问题吗?而且,通过将每个元素转换为字符串,将整数列表作为字符串列表传递给查询是否很好,就像我在这种情况下对 userId
所做的那样?这可能是问题所在吗?我该如何解决?感谢您的宝贵时间!
org.postgresql.util.PSQLException: ERROR: argument of AND must be type boolean, not type record.
The same problem happens to"AND (:status IS NULL OR (a.status IN :status)) "
我认为使用 COALESCE(:status) IS NULL
而不是 :status IS NULL
可以解决上述问题。