Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: Custom type woes





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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group