Olá, fiz uma trigger no ON UPDATE e INSERT da tabela PESSOA. No entanto, há
algo errado com o código, pois quando altero a tabela, dá um erro: "Error
while updating". Mas não me diz o erro dentro da trigger. Por isso gostaria
que alguém indicasse onde poderia estar o erro nessa trigger.
Obrigado.
Nelson.
CREATE OR REPLACE FUNCTION "public"."lex_tr_pessoa_fantasia" () RETURNS
trigger AS
$body$
declare old_idfantasia bigint;
declare new_idfantasia bigint;
declare registro record;
BEGIN
if (old.idfantasia is null) then
old_idfantasia := -1;
else
old_idfantasia := old.idfantasia;
end if;
if (new.idfantasia is null) then
new_idfantasia := -1;
else
new_idfantasia := new.idfantasia;
end if;
if (new_idfantasia <> old_idfantasia) then
if (new_idfantasia = -1) then
new.fantasia := null;
else
SELECT INTO registro fantasia FROM fantasia where id =
NEW.idfantasia;
NEW.fantasia := registro.fantasia;
end if;
end if;
RETURN NULL;
END;
$body$
LANGUAGE 'plpgsql' IMMUTABLE CALLED ON NULL INPUT SECURITY INVOKER;
_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br