JDBC problem with dates and ANYELEMENT type

From: "Peter" <peter(at)greatnowhere(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: JDBC problem with dates and ANYELEMENT type
Date: 2009-04-23 08:13:28
Message-ID: 00e701c9c3eb$625d43a0$2717cae0$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2009-04-24 02:35:49 Re: JDBC problem with dates and ANYELEMENT type
Previous Message j.random.programmer 2009-04-23 04:10:54 Re: Bug with duplicate column names via JDBC MetaData (ORDINAL_POSITION)