pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Mapping Java BigDecimal
Date: Tue, 19 Jan 2010 10:31:10 -0600
Message-ID: <4B5589EE020000250002E76C@gw.wicourts.gov> (raw)

Thomas Kellerer <spam_eater@gmx.net> wrote:
> Craig Ringer, 19.01.2010 05:37:
 
>> 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 ;)
 
Forget PostgreSQL for just a moment; try this in Java:
 
import java.math.BigDecimal;
class BigDecimalTests
{
    public static void main(String[] args)
    {
        BigDecimal x;
        x = new BigDecimal(3.000);
        System.out.println(x.toPlainString());
        x = new BigDecimal("3.000");
        System.out.println(x.toPlainString());
        x = new BigDecimal(1.01);
        System.out.println(x.toPlainString());
        x = new BigDecimal("1.01");
        System.out.println(x.toPlainString());
    }
}
 
For those without Java to play along at home, the result of
compiling and running this are:
 
3
3.000
1.0100000000000000088817841970012523233890533447265625
1.01
 
On top of that, in PostgreSQL '3.000' is *not* a character string,
as you are probably assuming.  It is treated as type UNKNOWN until
it has to be resolved (similar to the treatment of a NULL literal),
so it can be interpreted as a literal of some other type.
 
-Kevin




view thread (15+ messages)  latest in thread

Message-ID: <4B5589EE020000250002E76C@gw.wicourts.gov>
Permalink:  ../4B5589EE020000250002E76C@gw.wicourts.gov/
Also on:    postgresql.org/message-id/4B5589EE020000250002E76C@gw.wicourts.gov

 · 

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: Kevin.Grittner@wicourts.gov, spam_eater@gmx.net
  Subject: Re: Mapping Java BigDecimal
  In-Reply-To: <4B5589EE020000250002E76C@gw.wicourts.gov>
  References: <4B5589EE020000250002E76C@gw.wicourts.gov>

* 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