JDBC problem with dates and ANYELEMENT type - Mailing list pgsql-jdbc

From Peter
Subject JDBC problem with dates and ANYELEMENT type
Date
Msg-id 00e701c9c3eb$625d43a0$2717cae0$@com
Whole thread Raw
Responses Re: JDBC problem with dates and ANYELEMENT type
List pgsql-jdbc
We have a function that takes ANYELEMENT type. If the argument is date (set using setObject(column, datevariable,
Types.DATE))the server throws error: 

ERROR: could not determine polymorphic type because input has type "unknown"

I checked JDBC sources and seems like AbstractJdbc2Statement does this:

    public void setDate(int i, java.sql.Date d, java.util.Calendar cal) throws SQLException
    {
        checkClosed();

        if (d == null)
        {
            setNull(i, Types.DATE);
            return;
        }


        if (cal != null)
            cal = (Calendar)cal.clone();

        // We must use UNSPECIFIED here, or inserting a Date-with-timezone into a
        // timestamptz field does an unexpected rotation by the server's TimeZone:
        //
        // We want to interpret 2005/01/01 with calendar +0100 as
        // "local midnight in +0100", but if we go via date it interprets it
        // as local midnight in the server's timezone:

        // template1=# select '2005-01-01+0100'::timestamptz;
        //       timestamptz
        // ------------------------
        //  2005-01-01 02:00:00+03
        // (1 row)

        // template1=# select '2005-01-01+0100'::date::timestamptz;
        //       timestamptz
        // ------------------------
        //  2005-01-01 00:00:00+03
        // (1 row)

        bindString(i, connection.getTimestampUtils().toString(cal, d), Oid.UNSPECIFIED);
    }



So it indeed sets ‘unspecified’ type which works fine if your target datatype is defined, but fails miserably on
ANYELEMENT.

Any suggestions how to work around this so we can still use ANYELEMENT and pass in DATE?

Peter


pgsql-jdbc by date:

Previous
From: "j.random.programmer"
Date:
Subject: Re: Bug with duplicate column names via JDBC MetaData (ORDINAL_POSITION)
Next
From: Kris Jurka
Date:
Subject: Re: JDBC problem with dates and ANYELEMENT type