From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Luca Pireddu <luca@cs.ualberta.ca>
Cc: pgsql-sql@postgresql.org
Subject: Re: argument type problem with plpgsql function
Date: Tue, 22 Nov 2005 16:13:28 -0800 (PST)
Message-ID: <20051122161059.H87037@megazone.bigpanda.com> (raw)
In-Reply-To: <200511221708.10563.luca@cs.ualberta.ca>
References: <200511221708.10563.luca@cs.ualberta.ca>
On Tue, 22 Nov 2005, Luca Pireddu wrote:
> I wrote a little function that has to work with big numbers
>
> CREATE OR REPLACE FUNCTION blast_evalue(seq_len bigint, db_size bigint,
> bit_score double precision)
> RETURNS double precision AS $$
> BEGIN
> RETURN 2^(bit_score) * db_size * seq_len;
> END;
> $$
> LANGUAGE 'plpgsql'
> IMMUTABLE
> RETURNS NULL ON NULL INPUT;
>
> but it doesn't work properly unless I cast the db_size parameter when I call
> the function:
>
> select blast_evalue(273, 8903836, -55.4546);
> blast_evalue
> --------------
> 2430747228 <- wrong number. This is 273 * 8903836
> (1 row)
>
> select blast_evalue(273, 8903836::bigint, -55.4546);
> blast_evalue
> ---------------------
> 4.9231356421437e-08 <- that's correct
> (1 row)
>
> I don't understand why the cast is necessary. Is there a way to make this
> work without it?
I got the same answer (the second) for both calls from my 8.0 and 8.1
setups, what version were you trying on?
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sszabo@megazone.bigpanda.com, luca@cs.ualberta.ca
Subject: Re: argument type problem with plpgsql function
In-Reply-To: <20051122161059.H87037@megazone.bigpanda.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