From: | "Barry Lind" <blind(at)xythos(dot)com> |
---|---|
To: | "Kris Jurka" <books(at)ejurka(dot)com>, <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: datatype conversion thoughts |
Date: | 2004-10-11 17:59:58 |
Message-ID: | 03E7D3E231BB7B4A915A6581D4296CC6AEFE72@NSNOVPS00411.nacio.xythos.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Kris,
How would PGDataType relate to PGObject? I have always thought that
PGObject should be extended and used for all datatypes (not just
extensions).
--Barry
-----Original Message-----
From: Kris Jurka [mailto:books(at)ejurka(dot)com]
Sent: Saturday, October 09, 2004 12:20 AM
To: pgsql-jdbc(at)postgresql(dot)org
Subject: [JDBC] datatype conversion thoughts
I've been looking at a number of driver todo items that are all centered
around converting between datatypes. Specifically adding COPY support,
array handling, composite types (SQLInput/Ouptut), and binary data
transfer. All of these center around converting pg datatypes to Java
types and back.
The current driver currently operates on everything (except bytea) as a
String which is indeed easy to transform to and from with simple
operations like Integer.parseInt, but this only works if you're really
given an integer to begin with. The jdbc spec allows you to call getInt
on a variety of types, like floats, so it needs a fallback to handle
that.
Also the driver allows you to call getInt on the deprecated pg money
type.
This means that every time you call getInt() it has to perform
operations on the String it's given to determine if it's actually a
money value "-$12.11" and strip away the dollars sign. This can't be
good for performance.
Basically what I'd like to see is a datatype parsed only as the type it
actually is. We know what type the underlying data is, but at the
moment it's not used. For the money example above it would be parsed as
money and then converted to an int. This means you only pay the cost of
parsing the money type when you actually have money. This also cleans
up the other fallback parsing where say if we had a float column and
called getInt on it we wouldn't bother trying Integer.parseInt on it
first and then falling back to a float parsing method.
One way of doing this would be provide a PGDataType abstract class that
provided every getXXX method (getInt, getFloat, getBoolean, ...) which
had a default implementation of saying "Invalid conversion...". Then
for each datatype an implementation would be provided that could parse
the underlying data and perform whatever conversions that are applicable
on it. This would work the same way on the reverse side (converting
from java -> pg) as the implementation would provide a method for
converting to the format pg is expecting.
There are some isses about when and how this conversion happens
regarding excessive object creation or protecting a fixed set of these
objects from multithreaded access, but I just wanted to throw this basic
concept out there for any feedback.
Kris Jurka
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
From | Date | Subject | |
---|---|---|---|
Next Message | Kris Jurka | 2004-10-11 19:53:34 | Re: A solution to the SSL customizing problem |
Previous Message | Andrew Sullivan | 2004-10-11 17:20:08 | Re: OT? Database bridge for postgresql |