Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 173089FA4B9 for ; Tue, 2 Jan 2007 18:01:01 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 29335-10 for ; Tue, 2 Jan 2007 18:00:51 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.226]) by postgresql.org (Postfix) with ESMTP id 5213C9FA4B6 for ; Tue, 2 Jan 2007 18:00:54 -0400 (AST) Received: by wr-out-0506.google.com with SMTP id i30so907664wra for ; Tue, 02 Jan 2007 14:00:52 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=hf6Q2JzFW9f3aCNkrhwyup1+TMiAyJr/q2Gc9xrzIPaLZJzfGZs/sl2uqgeSFr/bmWX/oWaa64U3s3mo0EZtg8BvtVXXJH3RhSToq0s1vjrdgxNzP4WOVwQgQ8zHkdCmqEi6x++CnAzdzvsnpYKGnEuJ1Kam6LEawpPKDQFOawk= Received: by 10.78.204.1 with SMTP id b1mr4878116hug.1167775251466; Tue, 02 Jan 2007 14:00:51 -0800 (PST) Received: by 10.78.90.20 with HTTP; Tue, 2 Jan 2007 14:00:51 -0800 (PST) Message-ID: <3fccaa690701021400n4311e0a6t5fe08e2768606012@mail.gmail.com> Date: Tue, 2 Jan 2007 14:00:51 -0800 From: "Andres Olarte" To: "Jeanna Geier" Subject: Re: Calculated Fields in Postgres? Cc: "Pgsql-Jdbc@Postgresql.Org" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/6 X-Sequence-Number: 16371 This is not a JDBC question, that's a basic SQL question, but any way... You have some choices: 1- Use a view to show the data from the table plus the calculated fields. 2- Use a trigger to define the value of the calculated field on INSERT. Which one you use depends on the usage scenario, basically how a change of the mfg policy would affect you. However, you seem to have a problem with your table structure, so you should probably read a little bit about normalization. For example, it might make more sense to convert everything to days, and forget about the 'Life Units' field. On 1/2/07, Jeanna Geier wrote: > Hello List! > > Still trying to learn Postgres... =) I have a question on how/where to > define a calculated field in a table... > > Let's say I have a 'Replacement Cost' table with the following fields: > > Original Cost > Original Date > Life Expectancy > Life Units > > and I want to add a 'Mfg. Replace Date' field, which is a calculated field > with the following formula: > > IF ('Life Units' = NAV) > THEN (NAV) > ELSE > ( IF ('Life Units' = 'Day(s)'') > THEN (AddDate('Original Date,0,0,'Life Expectancy')) > ELSE > ( IF 'Life Units' = 'Month(s)'') > THEN (AddDate('Original Date',0,'Life Expectancy',0)) > ELSE > ( IF 'Life Units' = 'Year(s)'') > THEN (AddDate('Original Date','Life Expectancy',0.0)) > ELSE > (today)))) > > -------------------------------------------------------- > > How/where do I define this calculated field? > > Any help or guidance that anyone could provide will be greatly appreciated! > > If any more information is necessary from my end, please let me know. > > Thanks, > -Jeanna > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings >