postgres中“$ 1”或附近的语法错误

时间:2014-02-10 15:42:56

标签: postgresql greenplum

我正在尝试运行以下函数,我在" $ 1"或附近得到错误"语法错误 有人可以帮我解决这个问题。谢谢!

CREATE OR REPLACE FUNCTION vin_calc() RETURNS text AS
$BODY$
DECLARE
    r res%rowtype;
    i integer default 0;
    x  text;
    curs2 CURSOR FOR SELECT * FROM res;
BEGIN
    FOR r IN curs2 

    LOOP
    if(x!=r.prod_grp_nm)
    i=0 
    end

     i:=i+1;

     if (i=1)
      update res set duration =0 where CURRENT OF curs2;

     elsif(i=2)
     update res set duration =1 where CURRENT OF curs2;

     elsif(i>=3)
     update res set gwma_duration =0.75*lag(res.duration,1)+(0.125*r.dur) where CURRENT OF curs2;
     end    

    x:=r.prod_grp_nm;      

    END LOOP;
    RETURN 'yes';
END
$BODY$
LANGUAGE 'plpgsql' ;

0 个答案:

没有答案