Syntax error at or near ;

故事扮演 提交于 2019-12-25 04:26:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!