Answer the question
In order to leave comments, you need to log in
Inserting data into PostgreSQL table ends with an error?
Understanding trigger functions.
For this, a simple table was first 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;';
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();
INSERT INTO AplusB VALUES (100,200);
ERROR: missing FROM-clause entry for table "aplusb"
LINE 1:INSERT INTO ABresult VALUES (AplusB.A+AplusB.B)
^ QUERY
: INSERT INTO ABresult VALUES (AplusB.A+AplusB.B)
CONTEXT: PL/pgSQL function "absumm" line 3 at SQL statement
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question