I will understand with trigger functions. For this, first a simple table was created and a function was added:
CREATE TABLE AplusB (A integer, B integer); INSERT INTO AplusB VALUES (1,1); INSERT INTO AplusB VALUES (2,2); INSERT INTO AplusB VALUES (3,3); CREATE FUNCTION plus(integer, integer) RETURNS integer LANGUAGE SQL AS 'SELECT $1 + $2;'; After that, another label and a trigger function are created:
CREATE TABLE ABresult (result integer); CREATE FUNCTION ABsumm() returns TRIGGER AS 'BEGIN DELETE FROM ABresult; INSERT INTO ABresult VALUES (AplusB.A+AplusB.B); RETURN NULL; END;' LANGUAGE 'plpgsql'; CREATE TRIGGER makeABresult AFTER INSERT OR UPDATE OR DELETE ON AplusB FOR EACH STATEMENT execute procedure ABsumm(); After trying to insert:
INSERT INTO AplusB VALUES (100,200); An error occurs:
ERROR: missing FROM clause entry for table "aplusb" STRING 1: INSERT INTO ABresult VALUES (AplusB.A + AplusB.B) ^ REQUEST: INSERT INTO ABresult VALUES (AplusB.A + AplusB.B) CONTEXT: PL / pgSQL function "absumm" line 3 at SQL statement
What could be the problem?
(Source of examples: wiki.linuxformat.ru/wiki/LXF87-88:PostgreSQL)
AplusB.A+AplusB.B, becauseAplusBdoes not appear in your query. - etki