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?

有帮助吗?

解决方案

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

其他提示

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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top