Does PGInterval class handle iso_8601 intervalstyle?

From: Adam Mackler <psql-jdbc(at)mackler(dot)org>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Does PGInterval class handle iso_8601 intervalstyle?
Date: 2015-03-26 23:12:31
Message-ID: 20150326231231.GG42707@scruffle.mackler.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi: I'm using server version 9.4.1 and JDBC driver version 9.4-1201-jdbc41.

When I have my server's output format of the interval type
(intervalstyle) set to iso_8601, I get values such as:

"PT2H5M25.562249S"

which when passed to the PGInterval constructor:

new PGInterval("PT2H5M25.562249S")

yields a org.postgresql.util.PGInterval =

0 years 0 mons 0 days 0 hours 0 mins 0.00 secs

Clearly incorrect. I get the same result for the example of iso_8601
"Day-Time Interval" format given in section 8.5.5 of the manual:
"P3DT4H5M6S".

http://www.postgresql.org/docs/9.4/interactive/datatype-datetime.html#DATATYPE-INTERVAL-OUTPUT

The comments on lines 119-120 of the PGInterval class' source code
file suggest that this format should be parsed:

> This handles hours, minutes, seconds and microseconds for ISO intervals

https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/util/PGInterval.java#L119

Moreover, the javadoc for the setValue() method (used by the
constructor) claims that an "SQLException Is thrown if the string
representation has an unknown format," suggesting that if the given
format cannot be parsed it ought to raise an exception rather than
returning the wrong value.

https://github.com/pgjdbc/pgjdbc/blob/master/org/postgresql/util/PGInterval.java#L79

Is is possible to use the PGInterval class to parse interval literals
in the format that a server with intervalstyle set to iso_8601
produces? If so, how? If not, why not, and why is no exception
raised when trying to do so?

Thanks very much,
--
Adam Mackler

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jeremy Whiting 2015-03-27 11:26:05 Re: Multi insert statement and getUpdateCount().
Previous Message dmp 2015-03-26 19:41:22 Re: Multi insert statement and getUpdateCount().