Estou com outro problema. Tenho uma função em pgsql que é usada tanto no
update quanto no insert de uma tabela. Estou testando o insert e estou
recebendo um erro quando tento avaliar se a variável OLD é null.
ERRO: record "old" is not assigned yet
DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT: PL/pgSQL function "upd_ins_despesa" line 11 at IF
CREATE OR REPLACE FUNCTION veiculo.upd_ins_despesa() RETURNS trigger AS $$
DECLARE
vidvenda int;
BEGIN
SELECT idvenda FROM veiculo.veiculo
WHERE idveiculo=NEW.idveiculo
INTO vidvenda;
IF (vidvenda IS NOT NULL) THEN
IF (OLD IS NOT NULL) THEN // LINHA 11 AQUI!
IF ( OLD.montante == NEW.montante) THEN
RETURN NEW;
END IF;
END IF;
PERFORM venda.calculosVenda(NEW.idvenda);
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
Neste link
http://www.postgresql.org/docs/8.4/static/plpgsql-trigger.html
OLD
Data type RECORD; variable holding the old database row for
UPDATE/DELETE operations in row-level triggers. This variable is NULL in
statement-level triggers and for INSERT operations.
Se não me falha o ingles, quando estou inserindo um registro o valor da
variavel OLD é null. Como posso fazer essa verificação?
Mudei a linha 11 para
IF (TG_OP == 'UPDATE') THEN
Mas recebo outro erro:
ERRO: operador não existe: text == unknown
LINE 1: SELECT ( $1 == 'UPDATE')
^
HINT: Nenhum operador corresponde com o nome e o(s) tipo(s) de argumento(s)
informados. Você precisa adicionar conversões de tipo explícitas.
QUERY: SELECT ( $1 == 'UPDATE')
CONTEXT: PL/pgSQL function "upd_ins_despesa" line 11 at IF
--
View this message in context:
http://old.nabble.com/Problema-com-trigger-em-update-tp28129160p28133672.html
Sent from the PostgreSQL - Brasil mailing list archive at Nabble.com.
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral