Qual é a diferença entre uma atualização posterior e uma atualização anterior no PostgreSQL? Não consegui entender a diferença entre after update
e before update
porque parece que a função sempre foi executada antes da atualização.
Então fiz o seguinte exemplo:
Fiz uma função que atualiza uma tabela quando o status é typing
mas com um atraso de 10 segundos.
CREATE OR REPLACE FUNCTION fai_prueba()
RETURNS trigger AS
$BODY$
begin
if new.status = 'Typing' then
update image set status = 'ToTyping', path = 'Real path' from pg_sleep(5) where id = old.id;
end if;
return null;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION fai_prueba()
OWNER TO postgres;
então eu tenho o seguinte gatilho
create trigger tai
after update on image
for each row execute procedure fai_prueba();
mas quando executo um UPDATE a consulta não acaba até acabar o atraso
UPDATE image
SET path='fake path'
, status= 'Typing'
WHERE id=5;
>Query returned successfully: 0 rows affected, 10042 ms execution time.
Então, é possível que a consulta de atualização termine antes do gatilho?