pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adam Mackler <psql-jdbc@mackler.org>
To: pgsql-jdbc@postgresql.org
Subject: Does PGInterval class handle iso_8601 intervalstyle?
Date: Thu, 26 Mar 2015 19:12:31 -0400
Message-ID: <20150326231231.GG42707@scruffle.mackler.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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



view thread (2+ messages)  latest in thread

Message-ID: <20150326231231.GG42707@scruffle.mackler.org>
Permalink:  ../20150326231231.GG42707@scruffle.mackler.org/
Also on:    postgresql.org/message-id/20150326231231.GG42707@scruffle.mackler.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: psql-jdbc@mackler.org
  Subject: Re: Does PGInterval class handle iso_8601 intervalstyle?
  In-Reply-To: <20150326231231.GG42707@scruffle.mackler.org>
  References: <20150326231231.GG42707@scruffle.mackler.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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