org.postgresql.util.PSQLException: ERROR: operator does not exist: date = bytea on date null in native query JPA

2.2k views Asked by At

I would like to have a native query for Postgresql, however I could not make it work with dates. I can receive date as null, or date as date, so I like to work in both cases:

" case when coalesce (?3, null) = ?3 then true " +
" else p.start_date = ?3 end"

if ?3 is the third parameter and can be null and it is of type LocalDate

I tried many variations, but could not make it work for both cases, separately it will work:

  1. if coalesce (?3, null) = ?3 for date param null it will work
  2. if p.start_date = ?3 for date param != null it will work

The column in the database is date

Thanks:)

1

There are 1 answers

0
vikifor On

This worked for me :

 case when ?3 <> '' then p.start_date = (cast(?3 as date))
      else 1 = 1 end

So, I am passing string parameter and convert it to date, because nothing else worked for me