问题
I have many trigger functions, and for some there is a strange error: "Syntax error at or near ;
" Here is my code:
CREATE OR REPLACE FUNCTION zajisti_vyplnenost() RETURNS trigger AS $$
BEGIN
IF NEW.typ_vztahu != 1 THEN
RETURN NEW;
END IF;
IF NEW.nad.typ_sj = 1 THEN
IF NEW.nad.vrstva.vypln = true THEN
ELSE
RAISE EXCEPTION 'Totožné stratigrafické jednotky musejí být stejného typu!';
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER zajisti_vyplnenost
BEFORE INSERT OR UPDATE ON s_vztah
FOR EACH ROW
EXECUTE PROCEDURE zajisti_vyplnenost();
According to the debugger, the error should be on line 14 (with END;
). I tried to find something which might cause the problem, but this function looks like the others which don't trigger any errors. I looked on some documentation for function and END syntax in plpgsql, but with no joy, and semicolon makes the error quite Google unfriendly.
So which part of my syntax is wrong, and how to correct it?
回答1:
Looks like you forgot one END IF
:
IF NEW.nad.typ_sj = 1 THEN
IF NEW.nad.vrstva.vypln = true THEN
ELSE
RAISE EXCEPTION 'Totožné stratigrafické jednotky musejí být stejného typu!';
END IF;
END IF;
should be correct
回答2:
You missed and END IF
:
IF NEW.nad.typ_sj = 1 THEN
IF NEW.nad.vrstva.vypln = true THEN
ELSE
RAISE EXCEPTION 'Totožné stratigrafické jednotky musejí být stejného typu!';
END IF;
END IF;
来源:https://stackoverflow.com/questions/22526685/syntax-error-at-or-near