From: Oliver Jowett <oliver@opencloud.com>
To: Sylvain Leroux <sl20@wanadoo.fr>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Using BigInteger as argument to AbstractJdbc2Statement.setObject
Date: Thu, 06 Aug 2009 01:17:54 +1200
Message-ID: <4A798682.9080204@opencloud.com> (raw)
In-Reply-To: <4A798325.4030607@wanadoo.fr>
References: <4A79587F.6010603@wanadoo.fr>
<4A79694F.9060404@opencloud.com>
<4A798325.4030607@wanadoo.fr>
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
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: oliver@opencloud.com, sl20@wanadoo.fr
Subject: Re: Using BigInteger as argument to AbstractJdbc2Statement.setObject
In-Reply-To: <4A798682.9080204@opencloud.com>
References: <4A79587F.6010603@wanadoo.fr> <4A79694F.9060404@opencloud.com> <4A798325.4030607@wanadoo.fr> <4A798682.9080204@opencloud.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