pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Kellerer <spam_eater@gmx.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: Mapping Java BigDecimal
Date: Tue, 19 Jan 2010 17:00:59 +0100
Message-ID: <hj4kvq$2jf$1@ger.gmane.org> (raw)
In-Reply-To: <4B55371B.40105@postnewspapers.com.au>
References: <4B540B7D.1080306@b2bcentrum.cz>
	<4B541C40.9040206@postnewspapers.com.au>
	<407d949e1001180209v39e46a88v6d5a0e5a181a5d84@mail.gmail.com>
	<4B55371B.40105@postnewspapers.com.au>

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);
> CREATE TABLE ^
> 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:

3
3.0000
3.0000
3.0000

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.

Thomas







view thread (15+ messages)  latest in thread

Message-ID: <hj4kvq$2jf$1@ger.gmane.org>
Permalink:  ../hj4kvq$2jf$1@ger.gmane.org/
Also on:    postgresql.org/message-id/hj4kvq$2jf$1@ger.gmane.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: spam_eater@gmx.net
  Subject: Re: Mapping Java BigDecimal
  In-Reply-To: <hj4kvq$2jf$1@ger.gmane.org>
  References: <4B540B7D.1080306@b2bcentrum.cz> <4B541C40.9040206@postnewspapers.com.au> <407d949e1001180209v39e46a88v6d5a0e5a181a5d84@mail.gmail.com> <4B55371B.40105@postnewspapers.com.au> <hj4kvq$2jf$1@ger.gmane.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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