Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 8BF9A6357FB for ; Wed, 5 Aug 2009 10:19:05 -0300 (ADT) 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 79524-03-2 for ; Wed, 5 Aug 2009 13:18:54 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 3C764633AF9 for ; Wed, 5 Aug 2009 10:18:00 -0300 (ADT) Received: from 122-57-44-76.jetstream.xtra.co.nz ([122.57.44.76] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1MYgNQ-0002lL-GK; Thu, 06 Aug 2009 01:17:56 +1200 Message-ID: <4A798682.9080204@opencloud.com> Date: Thu, 06 Aug 2009 01:17:54 +1200 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.22 (X11/20090608) MIME-Version: 1.0 To: Sylvain Leroux CC: pgsql-jdbc@postgresql.org Subject: Re: Using BigInteger as argument to AbstractJdbc2Statement.setObject References: <4A79587F.6010603@wanadoo.fr> <4A79694F.9060404@opencloud.com> <4A798325.4030607@wanadoo.fr> In-Reply-To: <4A798325.4030607@wanadoo.fr> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200908/11 X-Sequence-Number: 19860 Sylvain Leroux wrote: > Hi, > > and first of all, thanks for your answer. > > Oliver Jowett a écrit : >> Why NUMERIC instead of an integer type? >> >> Might as well make setBigInteger() private if you're not also going to >> expose it on PGStatement (I don't think it needs to be exposed there) > According to the JDK doc, java.math.BigInteger provides > "arbitrary-precision integers". > The closest match will be NUMERIC since it allows up to 1000 digits. As > far as I know, the integer types have much narrower range. > > *Or* could it be required to inspect the BigInteger in order to use the > most appropriate type? But, I don't see any benefits here: it appears > not to be a problem to send a NUMERIC value for an INTEGER column - as > far as the value is in the supported range. But there's no implicit cast from NUMERIC to integer types, is there? (It'd lose precision) > oliver=# CREATE OR REPLACE FUNCTION test_numeric(int4) RETURNS int4 AS 'SELECT $1' LANGUAGE SQL; > CREATE FUNCTION > oliver=# PREPARE s1(int4) AS SELECT test_numeric($1); > PREPARE > oliver=# PREPARE s2(numeric) AS SELECT test_numeric($1); > ERROR: function test_numeric(numeric) does not exist > LINE 1: PREPARE s2(numeric) AS SELECT test_numeric($1); > ^ > HINT: No function matches the given name and argument types. You might need to add explicit type casts. > So my concern with mapping Jython integer value -> BigInteger -> NUMERIC is that you end up with a statement parameter that's not actually an integer, and so "stmt.setObject(1,1234567899999)" will fail in cases where you would expect an integer value to work. Selecting a target type based on the magnitude of the parameter value passed may work better; then at least you get obvious behavior for cases where the value can fit in an integer. -O