How can i implement commit and rollback in my postgres function , code is as below. rollback here is used in exceptional block
CREATE OR REPLACE FUNCTION test () RETURNS VOID AS $body$
DECLARE
test_var smallint;
BEGIN
FOR abc IN
(SELECT DISTINCT ID
FROM plantab abc
JOIN xxx_upl_att xxx_val ON zzz_val.idf_tec = abc.ID
)
LOOP
select * from abc_pk_attribut(abc.ID) into test_var;
select * from abc_pk_champ(abc.ID) into test_var;
select * from abc_pk_valeur(abc.ID) into test_var;
select * from abc_pk_m_att(abc.ID) into test_var;
PERFORM abc_pk_maj_avalorise(abc.ID);
PERFORM abc_pk_maj_ab_attr(abc.ID);
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
raise notice 'program_error';
END;
$body$
LANGUAGE PLPGSQL
SECURITY DEFINER
;