Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f63KDsa59639 for ; Tue, 3 Jul 2001 16:13:54 -0400 (EDT) (envelope-from pgsql-general-owner@postgresql.org) Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5QNW0a19714; Tue, 26 Jun 2001 19:32:00 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f5QNH5s12906; Tue, 26 Jun 2001 19:17:05 -0400 (EDT) (envelope-from news) From: "Sergei Pohilko" X-Newsgroups: comp.databases.postgresql.general,comp.databases.postgresql.sql Subject: Cast varchar to interval in plpgsql Date: Tue, 26 Jun 2001 16:15:45 -0700 Organization: OnePage Inc. Lines: 39 Message-ID: <9hb55g$cj1$1@news.tht.net> X-Complaints-To: scrappy@hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 To: pgsql-general@postgresql.org.pgsql-sql@postgresql.org X-Archive-Number: 200107/49 X-Sequence-Number: 11951 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