pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedDefault numeric scale of zero in JDBC?
3+ messages / 2 participants
[nested] [flat]
* Default numeric scale of zero in JDBC?
@ 2007-01-18 14:05 Todd Shoemaker <jtshoe11@yahoo.com>
0 siblings, 0 replies; 3+ messages in thread
From: Todd Shoemaker @ 2007-01-18 14:05 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
I have discovered that the jdbc driver apparently uses a default scale of zero decimal places for SQL numeric operators, including the sum() aggregate operator. For example, this query:
select (1.5 + 2);
This returns 4 from jdbc, but it returns 3.5 when run from within PGAdmin. The only way I can coerce the value to return decimal places is to explicity cast the value to a numeric with scale:
select cast(1.5 + 2 as numeric(10,2)) as value
This returns 3.5.
Also, queries like "select sum(value) from table" returns a rounded value, even though the column 'value' is numeric(16,2). Is there a magic vmparam or setting to default the precision at the jdbc driver level? I am trying to run a large existing system on PostgreSQL and it is not feasible to hunt down all numeric operations in thousands of classes to explicitly cast them. Have others have encountered this issue?
Thanks,
-Todd
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Default numeric scale of zero in JDBC?
@ 2007-01-18 17:05 Todd Shoemaker <jtshoe11@yahoo.com>
0 siblings, 1 reply; 3+ messages in thread
From: Todd Shoemaker @ 2007-01-18 17:05 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
I downloaded the jdbc source and noted that if I specified a default scale of 4 in AbstractJdbc2ResultSetMetadata.getScale() (if the column is numeric and the scale is -1), I received the desired results. I further updated the code to provide a private DEFAULT_NUMERIC_PRECISION that defaults to 4, which can be overridden with the System property org.postgresql.jdbc2.DEFAULT_NUMERIC_SCALE. I built this and tested it within Squirrel SQL and it works properly, and the system property is working to override this default. Would this be an update that the jdbc driver developers would be interested in?
I suppose my other question is, what do other JDBC drivers default this to? Also, does this imply that others do not use non-integer arithmetic with sql through JDBC?
-Todd
----- Original Message ----
From: Todd Shoemaker <jtshoe11@yahoo.com>
To: pgsql-jdbc@postgresql.org
Sent: Thursday, January 18, 2007 8:05:42 AM
Subject: [JDBC] Default numeric scale of zero in JDBC?
Hello,
I have discovered that the jdbc driver apparently uses a default scale of zero decimal places for SQL numeric operators, including the sum() aggregate operator. For example, this query:
select (1.5 + 2);
This returns 4 from jdbc, but it returns 3.5 when run from within PGAdmin. The only way I can coerce the value to return decimal places is to explicity cast the value to a numeric with scale:
select cast(1.5 + 2 as numeric(10,2)) as value
This returns 3.5.
Also, queries like "select sum(value) from table" returns a rounded value, even though the column 'value' is numeric(16,2). Is there a magic vmparam or setting to default the precision at the jdbc driver level? I am trying to run a large existing system on PostgreSQL and it is not feasible to hunt down all numeric operations in thousands of classes to explicitly cast them. Have others have encountered this issue?
Thanks,
-Todd
---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Default numeric scale of zero in JDBC?
@ 2007-01-18 21:54 Oliver Jowett <oliver@opencloud.com>
parent: Todd Shoemaker <jtshoe11@yahoo.com>
0 siblings, 0 replies; 3+ messages in thread
From: Oliver Jowett @ 2007-01-18 21:54 UTC (permalink / raw)
To: Todd Shoemaker <jtshoe11@yahoo.com>; +Cc: pgsql-jdbc
Todd Shoemaker wrote:
> Hello,
>
> I downloaded the jdbc source and noted that if I specified a default scale of 4 in AbstractJdbc2ResultSetMetadata.getScale() (if the column is numeric and the scale is -1), I received the desired results. I further updated the code to provide a private DEFAULT_NUMERIC_PRECISION that defaults to 4, which can be overridden with the System property org.postgresql.jdbc2.DEFAULT_NUMERIC_SCALE. I built this and tested it within Squirrel SQL and it works properly, and the system property is working to override this default. Would this be an update that the jdbc driver developers would be interested in?
>
> I suppose my other question is, what do other JDBC drivers default this to? Also, does this imply that others do not use non-integer arithmetic with sql through JDBC?
Given that the reported metadata scale does not affect what the driver
does at all, and all the computation is done on the server side, I'd say
that any rounding that is happening is happening in whatever is using
the driver's metadata ("Squirrel SQL?")
-O
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2007-01-18 21:54 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-01-18 14:05 Default numeric scale of zero in JDBC? Todd Shoemaker <jtshoe11@yahoo.com>
2007-01-18 17:05 Re: Default numeric scale of zero in JDBC? Todd Shoemaker <jtshoe11@yahoo.com>
2007-01-18 21:54 ` Oliver Jowett <oliver@opencloud.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