Thread: BUG #1073: JDBC "time with time zone"

BUG #1073: JDBC "time with time zone"

From
"PostgreSQL Bugs List"
Date:
The following bug has been logged online:

Bug reference:      1073
Logged by:          Bob Messenger

Email address:      bob@cassiancapital.com

PostgreSQL version: 7.5 Dev

Operating system:   Linux

Description:        JDBC "time with time zone"

Details:

create table a(b time with time zone);

insert into a values ('00:00:00');

import java.sql.*;

public class JDBC
{
    public JDBC()
    throws Exception
    {
    Class.forName("org.postgresql.Driver");
    DriverManager.setLogStream(System.out);
    Connection db =
DriverManager.getConnection("jdbc:postgresql://blah/blah?loglevel=3",
"postgres", null);

    Statement st = db.createStatement();
    ResultSet rs = st.executeQuery("SELECT b FROM a");
    while (rs.next())
    {
        System.out.println(rs.getString(1));
        System.out.println(rs.getTimestamp(1));
    }
    rs.close();
    st.close();
    db.close();
    }

    public final static void main(String args[])
    throws Exception
    {
    new JDBC();
    }
}

getConnection returning
driver[className=org.postgresql.Driver,org.postgresql.Driver@16f0472]
00:00:00+00
Exception in thread "main" org.postgresql.util.PSQLException: Bad Timestamp
Format at 2 in 00:00:00+00
org.postgresql.jdbc1.AbstractJdbc1ResultSet.toTimestamp(AbstractJdbc1Result
        at Set.java:1183)
org.postgresql.jdbc1.AbstractJdbc1ResultSet.getTimestamp(AbstractJdbc1Resul
        at tSet.java:376)
        at JDBC.<init>(JDBC.java:17)
        at JDBC.main(JDBC.java:27)

Re: BUG #1073: JDBC "time with time zone"

From
Kris Jurka
Date:
> Bug reference:      1073
> Logged by:          Bob Messenger
> Email address:      bob@cassiancapital.com
> Description:        JDBC "time with time zone"
>
> Details:
>
> create table a(b time with time zone);
>
> insert into a values ('00:00:00');
>
>         System.out.println(rs.getTimestamp(1));
>
> Exception in thread "main" org.postgresql.util.PSQLException: Bad Timestamp
> Format at 2 in 00:00:00+00

I have confirmed this bug.  getTimestamp handles neither time nor timetz,
getTime also does not handle timetz.  The fix for this is a little
complicated as the date/time/timestamp parsing is kind of messy, but I
will try to have a patch for this sometime this weekend.

Kris Jurka