提交无法成功解除

时间:2018-02-21 17:33:14

标签: postgresql plpgsql commit

我有以下代码:代码是从demoimage表到fitsheader表执行映射。如果我注释掉提交,我可以在不抱怨的情况下运行代码;线。但demoimage表并没有改变,这让我困惑这些时间。我在谷歌上搜索了很多问题,但没有结果。

CREATE OR REPLACE FUNCTION public.linkjpeg(
)
RETURNS TABLE(matchtext text) 
LANGUAGE 'plpgsql'

COST 100
VOLATILE 
ROWS 1000
AS $BODY$

DECLARE
v_jpeghref demoImage.href%type;
v_fitsHREF fitsheader."HREF"%type;
v_uid varchar(500);
v_count bigint;
c_jpeg cursor for SELECT href from demoImage;
c_fitsHREF cursor for select t."HREF" from fitsheader t;
array_matches text[];
array_fitsHREF text[];
array_imgHref text[];
v_arrayDim bigint;
fileBone varchar(500);
fileBoneFits char(500);
c_checkUID cursor for select v_uid=any(array_matches);
c_checkfitsHREF cursor for select v_fitsHREF = any(array_fitsHREF);
c_matchrow cursor for select t.id_fitsheader from fitsheader t where t."HREF" like '%'||fileBoneFits||'%';
v_idfits bigint;
v_matchedFitsHREF fitsheader."HREF"%type;
i bigint;
_sql text;
BEGIN
  i := 0;

  open c_jpeg;
  loop
    fetch c_jpeg into v_jpegHref;

    v_uid := substring(v_jpegHref from '/member.uid.*');
      if(v_uid is not null) then

        array_imgHref := string_to_array(v_uid,'.');

        v_arrayDim := cardinality(array_imgHref);
        fileBone := array_to_string(array_imgHref[1:v_arrayDim-3],'.');
        -- replace xxxxx-x-xxxxxS. with null
        fileBoneFits := regexp_replace(filebone,'\d\d\d\d.\d.\d\d\d\d\d.S-','');

   open c_matchrow;
      begin
        fetch c_matchrow into v_idfits;
      exception 
        when others then
          raise notice '%','not found v_idfits';
        end;
        raise notice '%','v_idfits'||v_idfits;
        begin
          execute 'update demoImage set id_fitsheader='|| v_idfits ||' where href ='||quote_literal(v_jpegHref);
          **commit;**
          exception 
            when others then      
              raise notice '%','commit failed'||fileBoneFits;
          end;
        i := i+1;
        raise notice '%', i;
  close c_matchrow;
  end if;
  end loop;
  close c_jpeg;
END

问题是我永远无法成功执行提交。我可以分别在psql窗口中成功运行提交上面的sql。任何人都可以帮我弄清楚我错在哪里?提前谢谢!

1 个答案:

答案 0 :(得分:0)

PL / pgSQL函数中不能包含COMMITROLLBACK等事务语句;该功能将在v11中提供。