pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feednumeric type
10+ messages / 5 participants
[nested] [flat]
* numeric type
@ 2008-07-20 10:32 Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 10+ messages in thread
From: Peter @ 2008-07-20 10:32 UTC (permalink / raw)
To: pgsql-jdbc
For numeric types (with no explicit scale and precision) JDBC returns 0 for
both precision and scale (ResultSetMetaData.getPrecision and getScale
methods). This is breaking my app and IMO does not reflect true state of
things since Postgres docs state: "NUMERIC without any precision or scale
creates a column in which numeric values of any precision and scale can be
stored, up to the implementation limit on precision".
Shouldn't PG JDBC driver return maximum possible values for precision and
scale in such cases?
Peter
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
@ 2008-07-29 04:17 ` Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Re: numeric type Peter <peter@greatnowhere.com>
0 siblings, 1 reply; 10+ messages in thread
From: Kris Jurka @ 2008-07-29 04:17 UTC (permalink / raw)
To: Peter <peter@greatnowhere.com>; +Cc: pgsql-jdbc
On Sun, 20 Jul 2008, Peter wrote:
> For numeric types (with no explicit scale and precision) JDBC returns 0 for
> both precision and scale (ResultSetMetaData.getPrecision and getScale
> methods). This is breaking my app and IMO does not reflect true state of
> things since Postgres docs state: "NUMERIC without any precision or scale
> creates a column in which numeric values of any precision and scale can be
> stored, up to the implementation limit on precision".
>
> Shouldn't PG JDBC driver return maximum possible values for precision and
> scale in such cases?
>
There are a couple of issues here:
1) While PG supports larger numeric values, the maximum precision you can
constrain it to is 1000.
jurka=# create temp table tt (a numeric (1001, 1));
ERROR: NUMERIC precision 1001 must be between 1 and 1000
So do you return 1000 as the maximum precision because that's the maximum
that they can pass into create table even if they might actually receive a
value back that has a higher precision? Or do you return something larger
(the internal pg limit which I don't know offhand) even though they can't
create a table column with that limit?
2) Once you've set the maximum precision, how do you set the maximum
scale as the scale is a dependent on the precision. Is it (1000,500) ?
(1000, 0)? (1000, 1000)?
What we do now certainly isn't all that great, but I haven't heard a
concrete suggestion on what's better.
Kris Jurka
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
@ 2008-07-29 07:36 ` Peter <peter@greatnowhere.com>
2008-07-29 17:09 ` Re: numeric type Kris Jurka <books@ejurka.com>
0 siblings, 1 reply; 10+ messages in thread
From: Peter @ 2008-07-29 07:36 UTC (permalink / raw)
To: 'Kris Jurka' <books@ejurka.com>; +Cc: pgsql-jdbc
>> For numeric types (with no explicit scale and precision) JDBC returns 0
for
>> both precision and scale (ResultSetMetaData.getPrecision and getScale
>> methods). This is breaking my app and IMO does not reflect true state of
>> things since Postgres docs state: "NUMERIC without any precision or scale
>> creates a column in which numeric values of any precision and scale can
be
>> stored, up to the implementation limit on precision".
>>
>> Shouldn't PG JDBC driver return maximum possible values for precision and
>> scale in such cases?
>>
>
> There are a couple of issues here:
>
> 1) While PG supports larger numeric values, the maximum precision you can
> constrain it to is 1000.
>
> jurka=# create temp table tt (a numeric (1001, 1));
> ERROR: NUMERIC precision 1001 must be between 1 and 1000
>
> So do you return 1000 as the maximum precision because that's the maximum
> that they can pass into create table even if they might actually receive a
> value back that has a higher precision? Or do you return something larger
> (the internal pg limit which I don't know offhand) even though they can't
> create a table column with that limit?
> What we do now certainly isn't all that great, but I haven't heard a
> concrete suggestion on what's better.
OK, I hear ya. How about allowing user to set the default precision and
scale values for "numeric" type? Not sure how this would be done in JDBC
world but should be doable.
IMO a reasonable default maxing out both precision and scale (1000,500)
should work for most applications. Numeric type is not all that common
anyway.
Peter
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Re: numeric type Peter <peter@greatnowhere.com>
@ 2008-07-29 17:09 ` Kris Jurka <books@ejurka.com>
2008-07-29 21:23 ` Re: numeric type Peter Zeltins <peter@greatnowhere.com>
0 siblings, 1 reply; 10+ messages in thread
From: Kris Jurka @ 2008-07-29 17:09 UTC (permalink / raw)
To: Peter <peter@greatnowhere.com>; +Cc: pgsql-jdbc
On Tue, 29 Jul 2008, Peter wrote:
> OK, I hear ya. How about allowing user to set the default precision and
> scale values for "numeric" type? Not sure how this would be done in JDBC
> world but should be doable.
You could add URL parameters like unspecifiedNumericPrecision=1000 and
unspecificedNumericScale=500, but the tradeoff is how much work is it to
add these options to the URL parsing code and then pass them around, add
it to the datasource implementation, add it to the documentation, and ...
If there was some big important app that everyone wanted to use that blew
up on this I'd bet we'd do it, but I haven't heard a whole lot of
complaints about this problem.
Is this an important issue for other people?
Kris Jurka
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Re: numeric type Peter <peter@greatnowhere.com>
2008-07-29 17:09 ` Re: numeric type Kris Jurka <books@ejurka.com>
@ 2008-07-29 21:23 ` Peter Zeltins <peter@greatnowhere.com>
2008-07-30 08:24 ` Re: numeric type Daniel Migowski <dmigowski@ikoffice.de>
0 siblings, 1 reply; 10+ messages in thread
From: Peter Zeltins @ 2008-07-29 21:23 UTC (permalink / raw)
To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc
> > OK, I hear ya. How about allowing user to set the default precision and
> > scale values for "numeric" type? Not sure how this would be done in JDBC
> > world but should be doable.
>
> You could add URL parameters like unspecifiedNumericPrecision=1000 and
> unspecificedNumericScale=500, but the tradeoff is how much work is it to
> add these options to the URL parsing code and then pass them around, add
> it to the datasource implementation, add it to the documentation, and ...
>
> If there was some big important app that everyone wanted to use that blew
> up on this I'd bet we'd do it, but I haven't heard a whole lot of
> complaints about this problem.
I would assume this is not a major issue for most. Personally I ran into
this problem when writing automated PG->MS Access converter (Jackcess is
the only lib capable of creating MDB files on Linux/BSD) and it bailed
on numeric fields.
Peter
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Re: numeric type Peter <peter@greatnowhere.com>
2008-07-29 17:09 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 21:23 ` Re: numeric type Peter Zeltins <peter@greatnowhere.com>
@ 2008-07-30 08:24 ` Daniel Migowski <dmigowski@ikoffice.de>
2008-07-30 08:34 ` Re: numeric type Peter <peter@greatnowhere.com>
0 siblings, 1 reply; 10+ messages in thread
From: Daniel Migowski @ 2008-07-30 08:24 UTC (permalink / raw)
To: Peter Zeltins <peter@greatnowhere.com>; +Cc: pgsql-jdbc
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Peter,<br>
<br>
Peter Zeltins schrieb:
<blockquote cite="mid:1217366613.5193.11.camel@peter-laptop" type="cite">
<pre wrap="">
I would assume this is not a major issue for most. Personally I ran into
this problem when writing automated PG->MS Access converter (Jackcess is
the only lib capable of creating MDB files on Linux/BSD) and it bailed
on numeric fields.
</pre>
</blockquote>
Great gods, why would anyone do this in the first place? :) I once
wrote one for the opposite direction, but please tell us, which
requirements needs you to convert a postgres database to MS Access?<br>
<br>
With best regards,<br>
Daniel Migowski<br>
<div class="moz-signature">-- <br>
<pre> |¯¯|¯¯| <b>IKOffice GmbH Daniel Migowski</b>
| | |/| Mail: <a
href="mailto:dmigowski@ikoffice.de">dmigowski@ikoffice.de</a>
| | // | Nordstr. 10 Tel.: 0441 21 98 89 52
| | \\ | 26135 Oldenburg Fax.: 0441 21 98 89 55
|__|__|\| <a href="http://www.ikoffice.de">http://www.ikoffice.de</a; Mob.: 0176 22 31 20 76</pre>
</div>
</body>
</html>
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Re: numeric type Peter <peter@greatnowhere.com>
2008-07-29 17:09 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 21:23 ` Re: numeric type Peter Zeltins <peter@greatnowhere.com>
2008-07-30 08:24 ` Re: numeric type Daniel Migowski <dmigowski@ikoffice.de>
@ 2008-07-30 08:34 ` Peter <peter@greatnowhere.com>
2008-07-30 08:39 ` Re: numeric type Daniel Migowski <dmigowski@ikoffice.de>
0 siblings, 1 reply; 10+ messages in thread
From: Peter @ 2008-07-30 08:34 UTC (permalink / raw)
To: 'Daniel Migowski' <dmigowski@ikoffice.de>; +Cc: pgsql-jdbc
From: Daniel Migowski [mailto:dmigowski@ikoffice.de]
Sent: Wednesday, July 30, 2008 11:25 AM
To: Peter Zeltins
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] numeric type
I would assume this is not a major issue for most. Personally I ran into
this problem when writing automated PG->MS Access converter (Jackcess is
the only lib capable of creating MDB files on Linux/BSD) and it bailed
on numeric fields.
Great gods, why would anyone do this in the first place? :) I once wrote one
for the opposite direction, but please tell us, which requirements needs you
to convert a postgres database to MS Access?
Long story. We're migrating old Access app to Postgres but still need to be
able to exchange datasets with the old app users (app supports it's own
import/export in MDB format). Since migration is expected to last several
years we need some sort of automated PG->MDB thing.
Peter
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Re: numeric type Peter <peter@greatnowhere.com>
2008-07-29 17:09 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 21:23 ` Re: numeric type Peter Zeltins <peter@greatnowhere.com>
2008-07-30 08:24 ` Re: numeric type Daniel Migowski <dmigowski@ikoffice.de>
2008-07-30 08:34 ` Re: numeric type Peter <peter@greatnowhere.com>
@ 2008-07-30 08:39 ` Daniel Migowski <dmigowski@ikoffice.de>
2008-07-30 08:45 ` Re: numeric type Peter <peter@greatnowhere.com>
0 siblings, 1 reply; 10+ messages in thread
From: Daniel Migowski @ 2008-07-30 08:39 UTC (permalink / raw)
To: Peter <peter@greatnowhere.com>; +Cc: pgsql-jdbc
Hello Peter,
Peter schrieb:
>
>
>
> Long story. We’re migrating old Access app to Postgres but still need
> to be able to exchange datasets with the old app users (app supports
> it’s own import/export in MDB format). Since migration is expected to
> last several years we need some sort of automated PG->MDB thing…
>
Why don't you just make you converter configurable on how it handles
decimal without specs?
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Re: numeric type Peter <peter@greatnowhere.com>
2008-07-29 17:09 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 21:23 ` Re: numeric type Peter Zeltins <peter@greatnowhere.com>
2008-07-30 08:24 ` Re: numeric type Daniel Migowski <dmigowski@ikoffice.de>
2008-07-30 08:34 ` Re: numeric type Peter <peter@greatnowhere.com>
2008-07-30 08:39 ` Re: numeric type Daniel Migowski <dmigowski@ikoffice.de>
@ 2008-07-30 08:45 ` Peter <peter@greatnowhere.com>
2008-07-30 09:12 ` Re: numeric type tivvpgsqljdbc@gtech-ua.com
0 siblings, 1 reply; 10+ messages in thread
From: Peter @ 2008-07-30 08:45 UTC (permalink / raw)
To: 'Daniel Migowski' <dmigowski@ikoffice.de>; +Cc: pgsql-jdbc
>> Long story. We're migrating old Access app to Postgres but still need
>> to be able to exchange datasets with the old app users (app supports
>> it's own import/export in MDB format). Since migration is expected to
>> last several years we need some sort of automated PG->MDB thing.
>>
>Why don't you just make you converter configurable on how it handles
>decimal without specs?
I would need to hack Jackcess library in order to do that... besides it does
not seem the proper way to do it, more like an ugly hack. getPrecision and
getScale are supposed to return the true precision and scale after all...
Peter
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: numeric type
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Re: numeric type Peter <peter@greatnowhere.com>
2008-07-29 17:09 ` Re: numeric type Kris Jurka <books@ejurka.com>
2008-07-29 21:23 ` Re: numeric type Peter Zeltins <peter@greatnowhere.com>
2008-07-30 08:24 ` Re: numeric type Daniel Migowski <dmigowski@ikoffice.de>
2008-07-30 08:34 ` Re: numeric type Peter <peter@greatnowhere.com>
2008-07-30 08:39 ` Re: numeric type Daniel Migowski <dmigowski@ikoffice.de>
2008-07-30 08:45 ` Re: numeric type Peter <peter@greatnowhere.com>
@ 2008-07-30 09:12 ` tivvpgsqljdbc@gtech-ua.com
0 siblings, 0 replies; 10+ messages in thread
From: tivvpgsqljdbc@gtech-ua.com @ 2008-07-30 09:12 UTC (permalink / raw)
To: ; +Cc: pgsql-jdbc
Peter написав(ла):
>>> Long story. We're migrating old Access app to Postgres but still need
>>> to be able to exchange datasets with the old app users (app supports
>>> it's own import/export in MDB format). Since migration is expected to
>>> last several years we need some sort of automated PG->MDB thing.
>>>
>>>
>> Why don't you just make you converter configurable on how it handles
>> decimal without specs?
>>
>
> I would need to hack Jackcess library in order to do that... besides it does
> not seem the proper way to do it, more like an ugly hack. getPrecision and
> getScale are supposed to return the true precision and scale after all...
>
> Peter
>
>
It may be easier to write a wrapper over JDBC driver doing needed
conversion. With Java Proxy it is not a complex task.
It may look much like the next:
public class DelegatingHandler<TP> implements InvocationHandler {
protected final TP parent;
public DelegatingHandler(TP parent) {
this.parent = parent;
}
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
Method override =
this.getClass().getMethod(method.getName(), method.getParameterTypes());
if (override != null)
return override.invoke(this, args);
return method.invoke(parent, args);
}
}
public class ConnectionWrapper extends DelegatingHandler<Connection> {
public static Connection makeConnectionWrapper(Connection connection) {
return (Connection)
Proxy.newProxyInstance(ConnectionWrapper.class.getClassLoader(),
new Class[]{Connection.class}, new
ConnectionWrapper(connection));
}
...
public PreparedStatement prepareStatement(String sql) throws
SQLException {
return makePreparedStatementWrapper(parent.prepareStatement(sql));
}
...
}
You simply create a wrapper and "override" needed methods by making
methods in wrapper with exactly same name and signature, calling parent
instead of super when needed.
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2008-07-30 09:12 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-07-20 10:32 numeric type Peter <peter@greatnowhere.com>
2008-07-29 04:17 ` Kris Jurka <books@ejurka.com>
2008-07-29 07:36 ` Peter <peter@greatnowhere.com>
2008-07-29 17:09 ` Kris Jurka <books@ejurka.com>
2008-07-29 21:23 ` Peter Zeltins <peter@greatnowhere.com>
2008-07-30 08:24 ` Daniel Migowski <dmigowski@ikoffice.de>
2008-07-30 08:34 ` Peter <peter@greatnowhere.com>
2008-07-30 08:39 ` Daniel Migowski <dmigowski@ikoffice.de>
2008-07-30 08:45 ` Peter <peter@greatnowhere.com>
2008-07-30 09:12 ` tivvpgsqljdbc@gtech-ua.com
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