Hola!
hice una función que realiza un UPDATE y quería hacer un COMMIT dentro de la
función, pero me da el siguiente error:
ERROR: SPI_execute_plan failed executing query "commit": SPI_ERROR_TRANSACTION
CONTEXTO: PL/pgSQL function "cambia_clase" line 12 at sentencia SQL
La función es algo así:
CREATE FUNCTION cambia_clase() RETURNS VOID AS
$$
DECLARE
i INTEGER:= 0;
clasecorr CURSOR FOR select clasen,nro,mes from tmp_clase_correg;
BEGIN
FOR reg IN clasecorr LOOP
update tabla
set clasen = reg.clasen
where nro = reg.nro
and mes = reg.mes;
i := i + 1;
IF i = 1000 THEN
commit;
i := 0;
END if;
END LOOP;
END;
$$ LANGUAGE plpgsql;
Porqué me da error?
Gracias!