Nelson Pereira Júnior <[EMAIL PROTECTED]> escreveu:
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;



Verifique este SELECT:
SELECT INTO *registro fantasia* FROM fantasia where id =
NEW.idfantasia;

http://www.postgresql.org/docs/8.1/interactive/sql-selectinto.html

Você tem certeza que deseja retornar NULL?

[]s
Osvaldo


Abra sua conta no Yahoo! Mail - 1GB de espaço, alertas de e-mail no celular e anti-spam realmente eficaz.
_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br

Responder a