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

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: yuanhang(dot)zheng(at)qq(dot)com
Subject: BUG #16615: Cannot determine type of Date for "is null" expression
Date: 2020-09-13 00:28:45
Message-ID: 16615-1f85b569d6a34277@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 16615
Logged by: Hank
Email address: yuanhang(dot)zheng(at)qq(dot)com
PostgreSQL version: 13beta3
Operating system: Mac OS X
Description:

Steps to reproduce:
----------------------------
I am using Postgres JDBC driver 42.2.16.
Date date = new
SimpleDateFormat("yyyy-MM-dd").parse("2020-09-08");
String sql = "select * from tb_user where (? is null or
createdat > ?)";
PreparedStatement statement = conn.prepareStatement(sql);
statement.setDate(1, new java.sql.Date(date.getTime()));
statement.setDate(2, new java.sql.Date(date.getTime()));
ResultSet resultSet = statement.executeQuery();
Expected result:
------------------------
Can get result set successfully

Actual result:
ERROR: could not determine data type of parameter $1

After reading some codes of Postgres JDBC driver and Postgres server, the
following is my finding.
1. Postgres JDBC driver will always use Oid UNSPECIFIED(0) for Date type.
See PgPreparedStatement.java, in setDate function.
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.
case T_NullTest:
{
NullTest *n = (NullTest *) expr;
n->arg = (Expr *) transformExprRecurse(pstate, (Node *) n->arg);
/* the argument can be any type, so don't coerce it */
n->argisrow = type_is_rowtype(exprType((Node *) n->arg));
result = expr;
break;
}

Responses

Browse pgsql-bugs by date

  From Date Subject
Next 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
Previous Message Giorgio Saviane 2020-09-12 18:38:29 Re: BUG #16614: Stale temporary objects makes vacuum ineffective when 1 million transactions remain