X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 74371DBF32 for ; Tue, 22 Nov 2005 20:08:20 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17515-10 for ; Wed, 23 Nov 2005 00:08:19 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sunkay.cs.ualberta.ca (sunkay.cs.ualberta.ca [129.128.4.11]) by svr1.postgresql.org (Postfix) with ESMTP id 19232DBF2D for ; Tue, 22 Nov 2005 20:08:14 -0400 (AST) Received: from anzac.cs.ualberta.ca ([129.128.4.51]:36275 "EHLO smtp-auth.cs.ualberta.ca") by sunkay.cs.ualberta.ca with ESMTP id S556898AbVKWAIO (ORCPT ); Tue, 22 Nov 2005 17:08:14 -0700 Received: from [192.168.4.218] (nipisi.cs.ualberta.ca [129.128.4.7]) (using SSLv3 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by smtp-auth.cs.ualberta.ca (Postfix) with ESMTP id 4BCEA5CA01 for ; Tue, 22 Nov 2005 17:08:14 -0700 (MST) From: Luca Pireddu To: pgsql-sql@postgresql.org Subject: argument type problem with plpgsql function Date: Tue, 22 Nov 2005 17:08:09 -0700 User-Agent: KMail/1.8.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511221708.10563.luca@cs.ualberta.ca> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/212 X-Sequence-Number: 23463 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? Thanks Luca