I'm new to pgSQL ... I use version 9.5.0 and need to update a column every time a new record is inserted. The column must be populated from the values entered in area_pol and area_ofi.
I'm trying to create this function to meet my need:
CREATE OR REPLACE FUNCTION sch_cap.fc_atualiza_dif_area()
RETURNS trigger AS
$$
BEGIN
UPDATE
sch_cap.tbl_cap
SET
dif_area = abs(100 - (tbl_cap.area_pol / (tbl_cap.area_ofi * 100)));
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER tg_atualiza_dif_area BEFORE INSERT OR UPDATE ON sch_cap.tbl_cap FOR EACH ROW EXECUTE PROCEDURE sch_cap.fc_atualiza_dif_area();
But when I try to insert a record, the following msg is displayed: ERROR: stack depth limit exceeded HINT: Increase the configuration parameter "max_stack_depth" (currently 2048kB), after ensuring the platform's stack depth limit is adequate.