Received: from consumercontact.com ([209.167.202.12]) by hub.org (8.9.3/8.9.3) with ESMTP id PAA19916 for ; Wed, 5 Jan 2000 15:16:05 -0500 (EST) (envelope-from rick@consumercontact.com) Received: from consumercontact.com ([192.168.1.54]) by consumercontact.com (8.8.7/8.8.7) with ESMTP id PAA07107; Wed, 5 Jan 2000 15:09:11 -0500 Message-ID: <3873A61F.F012F9E8@consumercontact.com> Date: Wed, 05 Jan 2000 15:14:23 -0500 From: Rick Delaney X-Mailer: Mozilla 4.61 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 To: Tom Lane CC: pgsql-sql@postgreSQL.org Subject: Re: [SQL] Calculation dependencies in views References: <38728CE2.C1756D3E@consumercontact.com> <16341.947050503@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Tom Lane wrote: > > I think what you are getting at is avoiding duplicate computations, > such as the repeated evaluations of x + y in the above example? > > My guess is that you are wasting your time to worry about it, unless > the repeated calculations are *really* expensive (a float add is down > in the noise ... though a ten-thousand-digit NUMERIC trig function > might not be). I was more interested in reducing code complexity but this is good to know anyway. Thanks a lot for your help. Your last remark brings another question to mind. If I do this: rick=> CREATE TABLE foo (foo numeric(9,2)); CREATE rick=> CREATE VIEW bar AS SELECT foo * foo AS bar FROM foo; CREATE rick=> \d foo Table = foo +----------------------------------+--------------------------+-------+ | Field | Type | Length| +----------------------------------+--------------------------+-------+ | foo | numeric | 9.2 | +----------------------------------+--------------------------+-------+ rick=> \d bar View = bar Query = SELECT ("foo"."foo" * "foo"."foo") AS "bar" FROM "foo"; +----------------------------------+--------------------------+-------+ | Field | Type | Length| +----------------------------------+--------------------------+-------+ | bar | numeric |65535.65| +----------------------------------+--------------------------+-------+ ^^^^^^^^ What governs the precision of the numeric in the view "bar"? I couldn't find the specifics of this in the docs. Is it something I need to ever think of? If so, can I cast it to a smaller numeric? I think 18.4 should be sufficient in this case. Thanks again, --Rick