Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 8AB381337B95 for ; Sat, 5 Feb 2011 14:01:30 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 72821-06 for ; Sat, 5 Feb 2011 18:01:23 +0000 (UTC) X-Greylist: delayed 19:42:22.843896 by SQLgrey-1.7.6 Received: from mail-gy0-f174.google.com (mail-gy0-f174.google.com [209.85.160.174]) by mail.postgresql.org (Postfix) with ESMTP id 65CCD1337B54 for ; Sat, 5 Feb 2011 14:01:22 -0400 (AST) Received: by gyb11 with SMTP id 11so1294013gyb.19 for ; Sat, 05 Feb 2011 10:01:21 -0800 (PST) Received: by 10.146.83.8 with SMTP id g8mr1830533yab.11.1296928880968; Sat, 05 Feb 2011 10:01:20 -0800 (PST) Received: from [10.168.2.218] ([64.245.2.62]) by mx.google.com with ESMTPS id 35sm2662180ano.31.2011.02.05.10.01.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 05 Feb 2011 10:01:20 -0800 (PST) Message-ID: <4D4D9056.5070605@aquafold.com> Date: Sat, 05 Feb 2011 10:00:54 -0800 From: John LH User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100915 Lightning/1.0b2 Thunderbird/3.1.4 MIME-Version: 1.0 To: Kevin Grittner CC: pgsql-jdbc@postgresql.org Subject: Re: JDBC CallableStatement bug on functions with return parameter References: <4D4D37E5020000250003A45D@gw.wicourts.gov> In-Reply-To: <4D4D37E5020000250003A45D@gw.wicourts.gov> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.6 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201102/27 X-Sequence-Number: 21425 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 >