X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id D12EAD1B958 for ; Tue, 19 Aug 2003 13:20:21 -0300 (ADT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 96167-02 for ; Tue, 19 Aug 2003 13:20:11 -0300 (ADT) Received: from megazone.bigpanda.com (45.mufb.snfc.sffca01r18.dsl.att.net [12.103.249.45]) by svr1.postgresql.org (Postfix) with ESMTP id E72D6D1B97E for ; Tue, 19 Aug 2003 13:20:10 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id B8C26D66A; Tue, 19 Aug 2003 09:20:09 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id AA5E15C0A; Tue, 19 Aug 2003 09:20:09 -0700 (PDT) Date: Tue, 19 Aug 2003 09:20:09 -0700 (PDT) From: Stephan Szabo To: Rhaoni Chiu Pereira Cc: Subject: Re: Problems creating a function In-Reply-To: <1061309605.3f424ca5e30ee@sistemica.info> Message-ID: <20030819091906.S67349-100000@megazone.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/205 X-Sequence-Number: 9926 On Tue, 19 Aug 2003, Rhaoni Chiu Pereira wrote: > Hi List, > > > I was wondering if someone could help me out. I'm migrating a Oracle db to > PostgreSQL so I must rewrite the functions 'cuz the PL/pgSQL's sintax is > different. The problem is to sum dates .. as follows: > > CREATE FUNCTION ft_vcto_dupl(NUMERIC,NUMERIC,TIMESTAMP,NUMERIC,TIMESTAMP) > RETURNS TIMESTAMP AS ' > DECLARE > pEmp ALIAS FOR $1; > pFil ALIAS FOR $2; > pDataEmissao ALIAS FOR $3; > pCodigoPrazoPgto ALIAS FOR $4; > pPrazoPgtoFixo ALIAS FOR $5; > mDataVctoDupl TIMESTAMP := pPrazoPgtoFixo; > mPrazoPgto NUMERIC(3) := 0; > BEGIN > SELECT INTO mPrazoPgto prazo FROM ftpraz00 WHERE emp = pEmp AND fil = 0 > AND codigo = pCodigoPrazoPgto; > IF NVL(to_number(TO_CHAR(mDataVctoDupl,''MM'')),00) = 00 THEN > ***** mDataVctoDupl := pDataEmissao + mPrazoPgto; > END IF; > -- > RETURN (mDataVctoDupl); > END; > > ' LANGUAGE 'plpgsql' > > In the line marked with " ***** " it should be something like : > > mDataVctoDupl := pDataEmissao + interval ''mPrazoPgto day''; Perhaps you want something like: pDataEmissao + interval ''1 day'' * mPrazoPgto;