pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: sylvain-lemouzy-pfx (@sylvain-lemouzy-pfx) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #3845: Wrong result on equality between Date and Timestamp given as query parameter
Date: Wed, 22 Oct 2025 10:30:12 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

@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.

view thread (17+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #3845: Wrong result on equality between Date and Timestamp given as query parameter
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox