|
O que preciso eh que o campo NOME_FANTASIA da
tabela PESSOA seja colocado numa variavel RECORD de nome REGISTRO.
Por isso usei:
SELECT INTO registro nome_fantasia FROM tab_fantasia where id =
NEW.idfantasia;
e tentei também
SELECT nome_fantasia INTO registro FROM tab_fantasia where id =
NEW.idfantasia;
Mas ambos não deram certo.
O problema pode ser em outras linhas. Um erro de
sintaxe por exemplo. Mas nõ consigo identificar pois o PG não me mostra o erro.
Já passei 2 dias olhando esse código e não vi o problema.
----- Original Message -----
Sent: Saturday, May 06, 2006 11:22
AM
Subject: Re: [PostgreSQL-Brasil] O que há
de errado nessa TRIGGER?
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
|
_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br