Subject: [pgjdbc/pgjdbc] issue #2834: LocalTime.MAX is more precise than postgresql, causing a possible overflow to the next day

From: "tsayao (@tsayao)" <[email-masked]>
Date: Tue, 28 Feb 2023 20:31:26 +0000

**Describe the issue**

I am using Hibernate (5.6.14) with Spring Data JPA and pgjdbc 42.5.4.

When querying a column that is mapped to `LocalDateTime` with `LocalDate.atTime(LocalTime.MAX)` it returns results with the next day at 00:00:00.000000.

`LocalTime.MAX` is implemented as:

`MAX = new LocalTime(23, 59, 59, 999999999);`

**Driver Version?** 
42.5.4

**Java Version?**
17.0.4

**OS Version?**
Linux Ubuntu 20.04

**PostgreSQL Version?**
14.5

**To Reproduce**

```

create table test (
    col timestamp
);

insert into test(col) values ('2023-03-01 00:00:00.000000');
insert into test(col) values ('2023-02-28 23:59:59.999999');
```
```
public class Main {
    public static void main(String[] args) throws Exception {

        String url = "jdbc:postgresql://localhost:5432/database";

        Properties props = new Properties();
        props.setProperty("user", "login");
        props.setProperty("password", "pass");
        try (Connection conn = DriverManager.getConnection(url, props)) {
            try (var stmt = conn.prepareStatement("select col from test where col = ?")) {
                stmt.setTimestamp(1, Timestamp.valueOf(LocalDate.of(2023, 2, 28).atTime(LocalTime.MAX)));
                try (ResultSet rs = stmt.executeQuery()) {
                    if (rs.next())
                        System.out.println("Get String: " + rs.getString(1));
                }
            }
        }
    }
}

```
Prints out:

`Get String: 2023-03-01 00:00:00`

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Tue, 28 Feb 2023 20:42:06 +0000

Thanks for the report. Will look into it.

---

From: "motofix (@motofix)" <[email-masked]>
Date: Fri, 13 Mar 2026 14:31:23 +0000

I'm not sure that the issue is specific to `pgjdbc`, as `psql` have the same behaviour:
```none
create table test (
    col timestamp
);

select col from test where col = '2023-02-28 23:59:59.999999999';
         col
---------------------
 2023-03-01 00:00:00
(1 row)
```
Knowing this nanoseconds rounding to microseconds limitation, maybe `pgjdbc` should truncate to microseconds ?

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Tue, 17 Mar 2026 10:48:33 +0000

Touching time/date has historically been problematic. If this isn't a glaring bug, I'm inclined to let sleeping dogs lay.