X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 8E1D39FA2A9 for ; Fri, 30 Jun 2006 17:05:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 06354-03 for ; Fri, 30 Jun 2006 17:05:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail63.csoft.net (mail63.csoft.net [205.205.214.4]) by postgresql.org (Postfix) with SMTP id 600C09FA0EC for ; Fri, 30 Jun 2006 17:05:37 -0300 (ADT) Received: (qmail 4866 invoked by uid 1112); 30 Jun 2006 20:05:31 -0000 Date: Fri, 30 Jun 2006 15:05:31 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary2.csoft.net To: CG cc: pgsql-jdbc@postgresql.org Subject: Re: Custom type woes In-Reply-To: <20060630194335.95801.qmail@web37912.mail.mud.yahoo.com> Message-ID: References: <20060630194335.95801.qmail@web37912.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/145 X-Sequence-Number: 15425 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