Good afternoon.
To update fields before or after events, you need to create a Trigger.
Below an example of Trigger:
CREATE OR REPLACE FUNCTION trg_update_conhecimento()
RETURNS trigger AS
$BODY$
BEGIN
INSERT INTO conta_corrente
(descricao, data, fg_debito, valor, numero)
VALUES
('CONHECIMENTO GERADO', CURRENT_DATE, true, NEW.frete_peso + NEW.frete_km, NEW.numero);
RETURN NEW;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
CREATE TRIGGER trigger_update_conhecimento
AFTER UPDATE
ON conhecimento
FOR EACH ROW
EXECUTE PROCEDURE trg_update_conhecimento();
The above Trigger does an Insert in the current count table after an update to the knowledge table.
Have you ever seen triggers? See: https://www.postgresql.org/docs/9.2/static/plpgsql-trigger.html
– Marconi