pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Magdalena Komorowska <meluzyna@w3.net.pl>
Cc: pgsql-sql@postgresql.org
Subject: Re: Date Interval
Date: Tue, 6 Dec 2005 11:54:05 -0500 (EST)
Message-ID: <200512061654.jB6Gs5d14178@candle.pha.pa.us> (raw)
In-Reply-To: <20051206135906.ECA9713E35@spinet.pl>

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



view thread (8+ messages)  latest in thread

Message-ID: <200512061654.jB6Gs5d14178@candle.pha.pa.us>
Permalink:  ../200512061654.jB6Gs5d14178@candle.pha.pa.us/
Also on:    postgresql.org/message-id/200512061654.jB6Gs5d14178@candle.pha.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pgman@candle.pha.pa.us, meluzyna@w3.net.pl
  Subject: Re: Date Interval
  In-Reply-To: <200512061654.jB6Gs5d14178@candle.pha.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox