pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter <peter@greatnowhere.com>
To: pgsql-jdbc@postgresql.org
Subject: JDBC problem with dates and ANYELEMENT type
Date: Thu, 23 Apr 2009 11:13:28 +0300
Message-ID: <00e701c9c3eb$625d43a0$2717cae0$@com> (raw)

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




view thread (6+ messages)  latest in thread

Message-ID: <00e701c9c3eb$625d43a0$2717cae0$@com>
Permalink:  ../00e701c9c3eb$625d43a0$2717cae0$@com/
Also on:    postgresql.org/message-id/00e701c9c3eb$625d43a0$2717cae0$@com

 · 

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: peter@greatnowhere.com
  Subject: Re: JDBC problem with dates and ANYELEMENT type
  In-Reply-To: <00e701c9c3eb$625d43a0$2717cae0$@com>
  References: <00e701c9c3eb$625d43a0$2717cae0$@com>

* 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