pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Sergei Pohilko <spohilko@onepage.com>
To: pgsql-general@postgresql.org.pgsql-sql
Subject: Cast varchar to interval in plpgsql
Date: Tue, 26 Jun 2001 16:15:45 -0700
Message-ID: <9hb55g$cj1$1@news.tht.net> (raw)

Hi,

I need to create a PL/pgSQL function to add months  (something like this):

CREATE
Function        ADD_MONTHS
  ( timestamp,                         -- start date
    int4  )                                -- number of months (>0 or <0)
RETURNS  timestamp           -- new date
AS '
DECLARE
   v_arg1    ALIAS FOR   $1;
   v_arg2    ALIAS FOR   $2;
   v_line2      varchar(100);
   v_qq         timestamp;
BEGIN
      v_line2   := ltrim(to_char(v_arg2,''999999''),'' '')||'' month'';

       select v_arg1+v_line2::interval
       into v_qq;

    RETURN v_qq;
END; -- Function ADD_MONTHS
' LANGUAGE 'plpgsql';
----------------------------------------

But get error message when try to call it:

>select add_months(now(),3);

>Cannot cast type 'varchar' to 'interval'


Any ideas?

Thanks.
Sergei Pohilko





Message-ID: <9hb55g$cj1$1@news.tht.net>
Permalink:  ../9hb55g$cj1$1@news.tht.net/
Also on:    postgresql.org/message-id/9hb55g$cj1$1@news.tht.net

 · 

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: spohilko@onepage.com, pgsql-general@postgresql.org.pgsql-sql
  Subject: Re: Cast varchar to interval in plpgsql
  In-Reply-To: <9hb55g$cj1$1@news.tht.net>

* 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