|
Nelson, dê uma olhada, mas acho q o prob é o
retorno.. se vc dá return NULL, o pg não grava nda no bd, o certo seria fazer
por exemplo
IF (TG_OP = 'UPDATE' OR TG_OP = 'INSERT')
THEN
RETURN NEW;
ELSE --DELETE
RETURN OLD;
END IF;
Espero ter ajudado :0)
----- Original Message -----
Sent: Wednesday, May 03, 2006 11:19
AM
Subject: [PostgreSQL-Brasil] Onde está o
erro nesta Trigger?
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.
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
No virus found in this incoming message. Checked by AVG Free
Edition. Version: 7.1.385 / Virus Database: 268.5.1/328 - Release Date:
1/5/2006
|
_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br