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 AF15B9DCCC4 for ; Tue, 6 Dec 2005 13:30:56 -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 48521-04 for ; Tue, 6 Dec 2005 13:30:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr2.postgresql.org (svr2.postgresql.org [65.19.161.25]) by postgresql.org (Postfix) with ESMTP id 2A4629DCCB8 for ; Tue, 6 Dec 2005 13:30:53 -0400 (AST) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by svr2.postgresql.org (Postfix) with ESMTP id A77B2F0C77 for ; Tue, 6 Dec 2005 17:30:53 +0000 (GMT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1EjgVN-0003AD-A9 for pgsql-sql@postgresql.org; Tue, 06 Dec 2005 18:21:29 +0100 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 06 Dec 2005 18:21:29 +0100 Received: from hf0923x by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 06 Dec 2005 18:21:29 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Re: Date Interval Date: 06 Dec 2005 18:15:24 +0100 Organization: Linux Private Site Lines: 38 Message-ID: <87k6eixi37.fsf@srv.protecting.net> References: <20051206135906.ECA9713E35@spinet.pl> <200512061654.jB6Gs5d14178@candle.pha.pa.us> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.332 required=5 tests=[RCVD_IN_BL_SPAMCOP_NET=1.332] X-Spam-Score: 1.332 X-Spam-Level: * X-Archive-Number: 200512/50 X-Sequence-Number: 23592 In article <200512061654.jB6Gs5d14178@candle.pha.pa.us>, Bruce Momjian writes: > 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) Since Magdalena doesn't store the number of months in a string, the following might be more convenient: SELECT date_in + interwal_months * INTERVAL '1 MONTH' FROM any_table