I've got the error :
ERROR: syntax error at or near "trigger" LINE 18: CREATE OR REPLACE trigger T1
ERROR: syntax error at or near "trigger" SQL state: 42601 Character: 391
for this code:
CREATE OR REPLACE FUNCTION trigf1() RETURNS trigger AS
$$
BEGIN
IF EXISTS ( SELECT*
FROM Receipt JOIN Sells ON Receipt.license = Sells.license
WHERE iname = NEW.iname AND cid = NEW.cid AND rno = NEW.rno
)THEN
RETURN NEW;
ELSE
RAISE NOTICE 'This cafe does not sell the item: %s',new.iname;
RETURN NULL;
END IF;
END;
$$
LANGUAGE 'plpgsql';
CREATE OR REPLACE TRIGGER T1
BEFORE INSERT OR UPDATE
ON Buys
FOR EACH ROW
EXECUTE PROCEDURE trigf1();
Any idea what is the problem?