pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: CG <cgg007@yahoo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Custom type woes
Date: Fri, 30 Jun 2006 15:05:31 -0500 (EST)
Message-ID: <Pine.BSO.4.63.0606301459170.29530@leary2.csoft.net> (raw)
In-Reply-To: <20060630194335.95801.qmail@web37912.mail.mud.yahoo.com>
References: <20060630194335.95801.qmail@web37912.mail.mud.yahoo.com>



On Fri, 30 Jun 2006, CG wrote:

> It still generated the "must use explicit cast" error on insert. My
> inexperience with jdbc really shows here. I must not have hooked in the new
> class in all the spots where it should be hooked. I created a
> PGuniqueidentifier.class with appropriate member data, constructors, and
> methods setValue, equals, clone, and getValue. I then hooked it in under
> org.postgresql.jdbc2.AbstractJdbc2Connection#initObjectTypes by adding the line
> addDataType("uniqueidentifier", org.postgresql.util.PGuniqueidentifier.class);
> I must be leaving something out.

The key thing you need to do is call setObject like so:

ps.setObject(1, new PGuniqueidentifier("stringdata"));

This is how it determines the type you're passing in.

>> It will still do that regardless of what you do.  What java.sql.Type would
>> you like it to use and how could it know that?
>
> Like MONEY uses double, I was hoping to map uniqueidentifier to VARCHAR... It
> wouldn't know unless someone told it. :) Perhaps putting something in under
> org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData#getColumns ? That also may
> be the wrong course of action.

For the moment all of the mappings to java.sql.Type values are hardcoded 
in org.postgresql.jdbc2.TypeInfoCache and money happens to have an entry 
for historical reasons, but no other extension type does.

If you really want it to operate exactly like text the easiest thing to do 
is just make it a text entry (possibly a domain on text) in the database. 
Yes, you'll waste some storage space, but perhaps that is acceptable.

Kris Jurka



view thread (4+ messages)

Message-ID: <Pine.BSO.4.63.0606301459170.29530@leary2.csoft.net>
Permalink:  ../Pine.BSO.4.63.0606301459170.29530@leary2.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.63.0606301459170.29530@leary2.csoft.net

 · 

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: books@ejurka.com, cgg007@yahoo.com
  Subject: Re: Custom type woes
  In-Reply-To: <Pine.BSO.4.63.0606301459170.29530@leary2.csoft.net>
  References: <20060630194335.95801.qmail@web37912.mail.mud.yahoo.com> <Pine.BSO.4.63.0606301459170.29530@leary2.csoft.net>

* 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