Re: BUG #16615: Cannot determine type of Date for "is null" expression - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #16615: Cannot determine type of Date for "is null" expression
Date
Msg-id 749016.1600008172@sss.pgh.pa.us
Whole thread Raw
In response to BUG #16615: Cannot determine type of Date for "is null" expression  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #16615: Cannot determine type of Date for "is null" expression  (yuanhang <yuanhang.zheng@qq.com>)
List pgsql-bugs
PG Bug reporting form <noreply@postgresql.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



pgsql-bugs by date:

Previous
From: Alexander Lakhin
Date:
Subject: Re: BUG #16272: Index expression can refer to wrong attributes if index is created via CREATE TABLE LIKE
Next
From: Tom Lane
Date:
Subject: Re: BUG #16272: Index expression can refer to wrong attributes if index is created via CREATE TABLE LIKE