pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John LH <johnlh@aquafold.com>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC CallableStatement bug on functions with	 return parameter
Date: Sat, 05 Feb 2011 10:00:54 -0800
Message-ID: <4D4D9056.5070605@aquafold.com> (raw)
In-Reply-To: <4D4D37E5020000250003A45D@gw.wicourts.gov>
References: <4D4D37E5020000250003A45D@gw.wicourts.gov>

  Hi,

 >> Try using BigDecimal, which *is* capable of storing exact 
representations of all decimal fractions.

In my previous email I mentioned that I also tried BigDecimal and it did 
not work.

 >> I've also tried the combination and results of ...
 >> ===
 >> java.sql.Types.DOUBLE/Double
 >> org.postgresql.util.PSQLException: ERROR: function 
public.sales_tax(double precision) does not exist
 >> ===
 >> java.sql.Types.NUMERIC/BigDecimal
 >> org.postgresql.util.PSQLException: ERROR: function 
public.sales_tax(numeric) does not exist

I am aware of the approximate datatype issue with Float and Double.  The 
reason I tried Float and Double is because if I call 
statement.execute("select * from tableWithMoney"), and then call 
ResultSet.getObject("money_column"), it will actually return a Double 
datatype.  Which is a possible bug in the JDBC driver.

I tried Float, Double and BigDecimal.  I can't find any documentation 
indicating what datatype to use.  Looking at the JDBC driver code it 
looks like it is incorrectly converting the SQL.

thanks
-John


On 2/5/2011 9:43 AM, Kevin Grittner wrote:
> John LH  wrote:
>
>> callStatement.registerOutParameter(1, java.sql.Types.FLOAT);
>
>> callStatement.setObject(2, new Float(25.25));
>
> PostgreSQL doesn't support using approximate data types (like Float)
> for money.  Try compiling and running this to see why:
>
> import java.math.BigDecimal;
> public class ExactnessTest
> {
>      public static void main(String[] args)
>      {
>          double approximate;
>          BigDecimal exact;
>
>          // Set an approximation of a penny.
>          approximate = 0.01;
>          // Put the actual value into an exact class.
>          exact = new BigDecimal(approximate);
>          // Show the actual value assigned to the double.
>          System.out.println(exact);
>          // Create and show an exact decimal penny.
>          exact = new BigDecimal("0.01");
>          System.out.println(exact);
>      }
> }
>
> Try using BigDecimal, which *is* capable of storing exact
> representations of all decimal fractions.  Note that feeding an
> approximate value, including an unquoted literal, to the BigDecimal
> constructor will cause the BigDecimal value to be less precise than
> you might expect.
>
> -Kevin
>



view thread (6+ messages)  latest in thread

Message-ID: <4D4D9056.5070605@aquafold.com>
Permalink:  ../4D4D9056.5070605@aquafold.com/
Also on:    postgresql.org/message-id/4D4D9056.5070605@aquafold.com

 · 

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: johnlh@aquafold.com, Kevin.Grittner@wicourts.gov
  Subject: Re: JDBC CallableStatement bug on functions with	 return parameter
  In-Reply-To: <4D4D9056.5070605@aquafold.com>
  References: <4D4D37E5020000250003A45D@gw.wicourts.gov> <4D4D9056.5070605@aquafold.com>

* 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