Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id A6AD9634E82 for ; Tue, 19 Jan 2010 12:01:40 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 37034-01 for ; Tue, 19 Jan 2010 16:01:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from lo.gmane.org (lo.gmane.org [80.91.229.12]) by mail.postgresql.org (Postfix) with ESMTP id E8C17633EFC for ; Tue, 19 Jan 2010 12:01:28 -0400 (AST) Received: from list by lo.gmane.org with local (Exim 4.50) id 1NXGWC-00035x-PM for pgsql-jdbc@postgresql.org; Tue, 19 Jan 2010 17:01:24 +0100 Received: from 217.110.94.67 ([217.110.94.67]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 19 Jan 2010 17:01:24 +0100 Received: from spam_eater by 217.110.94.67 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 19 Jan 2010 17:01:24 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: Mapping Java BigDecimal Date: Tue, 19 Jan 2010 17:00:59 +0100 Lines: 49 Message-ID: References: <4B540B7D.1080306@b2bcentrum.cz> <4B541C40.9040206@postnewspapers.com.au> <407d949e1001180209v39e46a88v6d5a0e5a181a5d84@mail.gmail.com> <4B55371B.40105@postnewspapers.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 217.110.94.67 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: <4B55371B.40105@postnewspapers.com.au> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.327 tagged_above=-10 required=5 tests=BAYES_20=-0.74, RCVD_NUMERIC_HELO=2.067 X-Spam-Level: * X-Archive-Number: 201001/52 X-Sequence-Number: 20248 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