Reputation: 1
I created a table ebill(name varchar, prev int, curr int)
. There is a trigger that raises an exception when values with prevreading = currreading
are entered. But it does not take other data also.
-- This is my function
CREATE OR REPLACE FUNCTION BILL_CHECK() RETURNS TRIGGER AS $$
BEGIN
IF (NEW.PREVREADING=NEW.CURRREADING) THEN
RAISE EXCEPTION 'Data Entry Error';
END IF;
RETURN NULL;
END;
$$ LANGUAGE PLPGSQL;
--This is my trigger
CREATE TRIGGER BILL
BEFORE INSERT OR UPDATE ON EBILL
FOR EACH ROW EXECUTE PROCEDURE BILL_CHECK();
INSERT INTO EBILL VALUES('MELVY',7,7);-- Raises Exception. Working.
NSERT INTO EBILL VALUES('MELVY',7,8);-- No change in the table.insert 00
INSERT 0 0
Why can't I insert the second group pf data?
Upvotes: 0
Views: 20
Reputation: 246133
The problem is that you return NULL
.
This is a signal to abort the data modification.
You should
RETURN NEW;
Upvotes: 1