Обсуждение: Does PGInterval class handle iso_8601 intervalstyle?

Поиск
Список
Период
Сортировка

Does PGInterval class handle iso_8601 intervalstyle?

От
Adam Mackler
Дата:
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


Re: Does PGInterval class handle iso_8601 intervalstyle?

От
Kris Jurka
Дата:

On Thu, 26 Mar 2015, Adam Mackler wrote:

> 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?
>

No it's not currently possible.  The PGInterval class was written prior to
the intervalstyle parameter being added in 8.4 and was never updated to
account for intervals in 8601 format.

Kris Jurka