i'm trying to make a trigger that checks when a row is entered into a table if a certain value in that row exists in another table. the tables i have are:
car, rent, request
the code i'm using:
CREATE OR REPLACE FUNCTION trigf1() RETURNS trigger AS $$
BEGIN
SELECT seats FROM car WHERE lno=new.lno;
IF seats=!(SELECT seats FROM request WHERE rno=new.rno)
THEN
raise exception 'assignment contradicts design'
END IF;
RETURN null;
END;
$$
CREATE TRIGGER 'T1' BEFORE INSERT ON rent
for each row
EXECUTE PROCEDURE trigf1( );
I get an error saying:
ERROR: syntax error at or near "CREATE"
LINE 13: CREATE TRIGGER 'T1' BEFORE INSERT IN rent
anyone knows why?
create trigger t1 ...- a_horse_with_no_name$$needs to be$$;. Without it you did not finish the function code. - Adrian Klaver