pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Does PGInterval class handle iso_8601 intervalstyle?
2+ messages / 2 participants
[nested] [flat]

* Does PGInterval class handle iso_8601 intervalstyle?
@ 2015-03-26 23:12  Adam Mackler <psql-jdbc@mackler.org>
  0 siblings, 1 reply; 2+ messages in thread

From: Adam Mackler @ 2015-03-26 23:12 UTC (permalink / raw)
  To: 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


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Does PGInterval class handle iso_8601 intervalstyle?
@ 2015-03-27 14:59  Kris Jurka <books@ejurka.com>
  parent: Adam Mackler <psql-jdbc@mackler.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Kris Jurka @ 2015-03-27 14:59 UTC (permalink / raw)
  To: Adam Mackler <psql-jdbc@mackler.org>; +Cc: pgsql-jdbc



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


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2015-03-27 14:59 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 23:12 Does PGInterval class handle iso_8601 intervalstyle? Adam Mackler <psql-jdbc@mackler.org>
2015-03-27 14:59 ` Kris Jurka <books@ejurka.com>

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