Re: Custom type woes

From: Kris Jurka <books(at)ejurka(dot)com>
To: CG <cgg007(at)yahoo(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Custom type woes
Date: 2006-06-30 20:05:31
Message-ID: Pine.BSO.4.63.0606301459170.29530@leary2.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Luis Vilar Flores 2006-06-30 23:24:51 Re: bytea memory improvement
Previous Message CG 2006-06-30 19:43:35 Re: Custom type woes