0

As stated in the title, I'm facing this issue when optional paramter(endDate) is null. It doesn't throw any error when both parameters are provided. I tried usin cast null as timestamp with time zone, cast as timestamp to both params in the query and it throws the same error. Please advise.

@Query("""
SELECT sets.companyId, COUNT(sets)
FROM WarehouseSetsEntity sets
WHERE (:endDate IS NULL AND sets.importDate >= :beginDate)
OR (:endDate  IS NOT NULL AND sets.importDate BETWEEN :beginDate  AND :endDate)
GROUP BY sets.companyId""")
List<Object[]> fetchCompanyByDateRange(@Param("beginDate")  OffsetDateTime beginDate,  @ Param("endDate") @NullableOffsetDateTime endDate);
Error:org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL [select wse1_0.companyid,count(wse1_0.setid) from sets wse1_0 where (coalesce(?,'1970-01-01T00 00:00Z') is null and wse1_0.import_date>=?) or (? is not null and wse1_0.import_date between ? and ?) group by wse1_0.companyid] [ERROR: could not determine data type of parameter $3] [n/a]; SQL [n/a]

1 Answer 1

1

Can you try using below code?

WHERE sets.importDate >= :beginDate AND (sets.importDate <= :endDate OR :endDate IS NULL)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.