X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4B44D9DCCC4 for ; Tue, 6 Dec 2005 12:54:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 41259-09 for ; Tue, 6 Dec 2005 12:54:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from candle.pha.pa.us (candle.pha.pa.us [64.139.89.126]) by postgresql.org (Postfix) with ESMTP id 8E6A49DCAB0 for ; Tue, 6 Dec 2005 12:54:10 -0400 (AST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id jB6Gs5d14178; Tue, 6 Dec 2005 11:54:05 -0500 (EST) From: Bruce Momjian Message-Id: <200512061654.jB6Gs5d14178@candle.pha.pa.us> Subject: Re: Date Interval In-Reply-To: <20051206135906.ECA9713E35@spinet.pl> To: Magdalena Komorowska Date: Tue, 6 Dec 2005 11:54:05 -0500 (EST) CC: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.014 required=5 tests=[AWL=0.014] X-Spam-Score: 0.014 X-Spam-Level: X-Archive-Number: 200512/47 X-Sequence-Number: 23589 Magdalena Komorowska wrote: > Hi, > I hale a problem with counting interwal and I can't find what to do with > this. > I have two fields in the table: > Column | Type | Modifiers > -----------------+---------+----------- > date_in | date | > interwal_months | numeric | > -----------------+---------+----------- > > Query > SELECT date_in + INTERVAL '3 MONTH' FROM any_table > works fine of course. > > However, how to do something like that? > SELECT date_in + INTERVAL ' interwal_months MONTH' FROM any_table How about this? test=> CREATE TABLE test(x TEXT); CREATE TABLE test=> INSERT INTO test VALUES ('3'); INSERT 0 1 test=> SELECT current_timestamp + cast(x || ' months' AS INTERVAL) FROM test; ?column? ------------------------------- 2006-03-06 11:53:05.574279-05 (1 row) -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073