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

Re: Mapping Java BigDecimal

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Mapping Java BigDecimal
Date: 2010-01-19 16:00:59
Message-ID: hj4kvq$2jf$ (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Craig Ringer, 19.01.2010 05:37:
>> In no case does postgres remember the precision of the input text. If
>> you don't specify a precision on the column it just prints as many as
>> necessar. That sounds like what you're looking for.
> Then I'm confused:
> regress=> create table test (x numeric);
> regress=> insert into test (x) values ('3');
> INSERT 0 1
> regress=> insert into test (x) values ('3.0');
> INSERT 0 1
> regress=> insert into test (x) values ('3.00');
> INSERT 0 1
> regress=> insert into test (x) values ('3.000');
> INSERT 0 1
> regress=> select * from test;
> x
> -------
> 3
> 3.0
> 3.00
> 3.000
> (4 rows)

My first question: why does anyone pass a numeric value as a string ;)

But it does not seem to matter whether a real value (without quotes) or a string is used for the above example.

I also tested this with my JDBC/Java based SQL client, which allows me to configure the number of decimals shown.
It uses a DecimalFormat to format the numbers returned from the JDBC driver.

When using the above example and configuring the client to show 4 decimals (which results in a format mask of "0.#" and calling setMaxDigits() with a value of 4) I will get:


Which is quite interesting as it seems that from the driver's point of view (or Java?) there is only a difference between no decimal digits or some decimal digits.  It does not seem to get (or request) the information  about how many decimals there were.

This seems to be done upon retrieving, because when inserting the above example data (again with or without quotes) from Java, the display in psql's display is the same as if the data had been inserted from psql.


In response to

pgsql-jdbc by date

Next:From: Kevin GrittnerDate: 2010-01-19 16:31:10
Subject: Re: Mapping Java BigDecimal
Previous:From: dmpDate: 2010-01-19 14:59:31
Subject: Re: Mapping Java BigDecimal

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group