Re: BUG #16615: Cannot determine type of Date for "is null" expression

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: yuanhang(dot)zheng(at)qq(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16615: Cannot determine type of Date for "is null" expression
Date: 2020-09-13 14:42:52
Message-ID: 749016.1600008172@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> 1. Postgres JDBC driver will always use Oid UNSPECIFIED(0) for Date type.
> See PgPreparedStatement.java, in setDate function.

You could ask the JDBC crew why they do that, although I suspect they
have reasons.

> 2. In Postgres server, it won't coerce the type to Date even if we provide
> the type. See parse_expr.c in transformExprRecurse function.

There's nothing to coerce it *to*.

I'd suggest working around this with something like

select * from tb_user where (?::date is null or createdat > ?)

Although TBH that query looks pretty fishy to start with. Do you
really want the entire table when the argument is null? Is it even
possible for the argument to be null --- I doubt Java has such a
thing as a null Date?

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2020-09-13 16:53:02 Re: BUG #16272: Index expression can refer to wrong attributes if index is created via CREATE TABLE LIKE
Previous Message Alexander Lakhin 2020-09-13 07:00:01 Re: BUG #16272: Index expression can refer to wrong attributes if index is created via CREATE TABLE LIKE