commit无法执行成功

commit can not be excueted successfully

我有以下代码:代码是做一个从 demoimage table 到 fitsheader table 的映射。如果我注释掉提交,我可以 运行 代码而不会抱怨;线。但是 demoimage table 没有改变,这让我很困惑。我在 google 上搜索了很多关于这个问题但没有得到结果。

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

问题是我永远无法使提交成功执行。我可以 运行 sql 上面的 sql 分别在 psql window 提交成功。谁能帮我弄清楚我错在哪里?提前致谢!

您不能在 PL/pgSQL 函数中包含 COMMITROLLBACK 等交易语句;该功能将在 v11 中可用。