Re: ResultSet.getObject(..., LocalTime.class) not working with Postgres timetz type

From: Mark Rotteveel <mark(at)lawinegevaar(dot)nl>
To: pgsql-jdbc(at)lists(dot)postgresql(dot)org
Subject: Re: ResultSet.getObject(..., LocalTime.class) not working with Postgres timetz type
Date: 2019-04-06 08:15:57
Message-ID: f42cc628-83c9-d009-707a-347126539b2d@lawinegevaar.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

For reference, the JDBC specification does not specify support
java.time.LocalXXX types on WITH TIME ZONE types.

Especially because it is rather ambiguous what local would mean: would
it mean local in the default JVM time zone, local at the original zone
or local at UTC?

Mark

On 6-4-2019 09:59, Thomas Kellerer wrote:
> Retrieving the value of a timetz column fails when using getObject(,
> LocalTime.class)
>
> Consider the following code:
>
>   Connection con = DriverManager.getConnection(...);
>   Statement stmt = con.createStatement();
>   ResultSet rs = stmt.executeQuery("select current_time");
>   rs.next();
>   LocalTime lt = rs.getObject(1, LocalTime.class);
>
> The above fails with:
>
> org.postgresql.util.PSQLException: Bad value for type
> timestamp/date/time: {1}
>     at
> org.postgresql.jdbc.TimestampUtils.toLocalTime(TimestampUtils.java:433)
>     at org.postgresql.jdbc.PgResultSet.getLocalTime(PgResultSet.java:563)
>     at org.postgresql.jdbc.PgResultSet.getObject(PgResultSet.java:3391)
>     at TestLocalTime.main(TestLocalTime.java:23)
> Caused by: java.time.format.DateTimeParseException: Text
> '09:48:19.747249+02' could not be parsed, unparsed text found at index 15
>     at
> java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1952)
>
>     at
> java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
>     at java.time.LocalTime.parse(LocalTime.java:441)
>     at java.time.LocalTime.parse(LocalTime.java:426)
>     at
> org.postgresql.jdbc.TimestampUtils.toLocalTime(TimestampUtils.java:430)
>
> getObject(1, OffsetTime.class) fails with "conversion to class
> java.time.OffsetTime from 92 not supported"
>
> I am not sure if this is the same as:
> https://github.com/pgjdbc/pgjdbc/issues/1048
> If it's not the same root cause, should I create an issue?
>
> Using "select localtime" instead, works just fine
>
>
> Regards
> Thomas
>
>
>
>
>

--
Mark Rotteveel

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Thomas Kellerer 2019-04-06 17:40:13 Re: ResultSet.getObject(..., LocalTime.class) not working with Postgres timetz type
Previous Message Thomas Kellerer 2019-04-06 07:59:13 ResultSet.getObject(..., LocalTime.class) not working with Postgres timetz type