Message-ID: From: "sylvain-lemouzy-pfx (@sylvain-lemouzy-pfx)" To: "pgjdbc/pgjdbc" Date: Wed, 22 Oct 2025 10:30:12 +0000 Subject: Re: [pgjdbc/pgjdbc] issue #3845: Wrong result on equality between Date and Timestamp given as query parameter In-Reply-To: References: List-Id: X-GitHub-Author-Login: sylvain-lemouzy-pfx X-GitHub-Comment-Id: 3431642806 X-GitHub-Comment-Type: issue_comment X-GitHub-Issue: 3845 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-Type: comment X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/issues/3845#issuecomment-3431642806 Content-Type: text/plain; charset=utf-8 @vlsi Just one thing. I understand it's not possible to tell exactly what parameter type it is when we use `setTimestamp()` but I don't get the reason why we couldn't determine the type of the parameter given by `setDate()`. As stated in the documentation `java.sql.Date` type is supposed to be used with zero valued time fields hence that should be exactly a sql `date` without any ambiguity. ``` import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDate; public class Repro { public static void main(String[] args) throws SQLException { String url = "jdbc:postgresql://localhost:5432/postgres"; String user = "postgres"; String password = "mysecretpassword"; Connection conn = DriverManager.getConnection(url, user, password); var date = java.sql.Date.valueOf(LocalDate.of(2013, 03, 21)); var preparedStatement = conn.prepareStatement( "SELECT pg_typeof(?) as theType"); preparedStatement.setDate(1, date); ResultSet rs = preparedStatement.executeQuery(); rs.next(); System.out.println("theType" + ": " + rs.getString("theType")); } } ``` this code throws the following exception and that's seams like not normal to me: ``` Exception in thread "main" org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $1 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2736) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2421) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:372) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:525) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:435) at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:196) at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:139) at Repro.main(Repro.java:22) ``` I understand this is related to an old api, maybe that's not worth fixing that. I'm just thinking there is a maybe a very quick fix to provide the correct type.