X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C284F5E46FB for ; Tue, 31 Aug 2004 09:35:13 -0300 (ADT) 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 88966-03 for ; Tue, 31 Aug 2004 12:35:04 +0000 (GMT) Received: from trade-india.com (unknown [203.101.29.7]) by svr1.postgresql.org (Postfix) with SMTP id B9C3B5E46EE for ; Tue, 31 Aug 2004 09:35:05 -0300 (ADT) Received: (qmail 24147 invoked from network); 31 Aug 2004 12:29:01 -0000 Received: from valium.trade-india-local.com (HELO ?192.168.0.100?) (192.168.0.100) by system66.trade-india-local.com with SMTP; 31 Aug 2004 12:29:01 -0000 Message-ID: <4134710D.70501@trade-india.com> Date: Tue, 31 Aug 2004 18:07:33 +0530 From: Rajesh Kumar Mallah User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Michael Glaesemann Cc: pgsql-sql@postgresql.org Subject: Re: Arbitrary precision arithmatic with pgsql References: <41346727.8080901@trade-india.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/339 X-Sequence-Number: 18836 Michael Glaesemann wrote: > > On Aug 31, 2004, at 8:55 PM, Rajesh Kumar Mallah wrote: > >> The docs says that numeric type supports numbers upto >> any precision > > > > >> However >> >> tradein_clients=# SELECT cast(2^100 as numeric); > > > > >> 1. Does the specs not require pgsql to print a warning or info , >> will it not be considered silient truncation of data. > > > AFAICS, the issue here is not the cast per se, but rather the power > operation (2^100), which expects a double precision argument. This > operation happens before the cast. Looks like the power operation of numeric ie, numeric ^ numeric already exists but it returns a double precision and the accuracy is getting lost. Shud numeric ^ numeric not be returning numeric instead? Regds mallah. tradein_clients=# CREATE TABLE t_a as SELECT 1::numeric ^ 1::numeric as col; SELECT tradein_clients=# \d t_a Table "public.t_a" +--------+------------------+-----------+ | Column | Type | Modifiers | +--------+------------------+-----------+ | col | double precision | | +--------+------------------+-----------+ > >> 2. Is there any way to do such calculation using pgsql, i understand >> bc is a better tool for it. > > > What you need is a power operation for numeric, which I think you'd > have to write yourself, possibly leveraging one of the procedural > languages (perhaps pl/perl) to access such an operation (as you > yourself mentioned). I'm sure you could find an algorithm to port to > PL/pgsql as well. > > Hope this helps. > > Michael Glaesemann > grzm myrealbox com > > > !DSPAM:41346ebe315451222497446! > > -- regds Mallah. Rajesh Kumar Mallah +---------------------------------------------------+ | Tradeindia.com (3,11,246) Registered Users | | Indias' Leading B2B eMarketPlace | | http://www.tradeindia.com/ | +---------------------------------------------------+