创建触发器功能是psql“语法错误在或接近”CREATE“”(Creating Trigger function is psql “syntax error at or near ”CREATE“”)

系统教程 行业动态 更新时间:2024-06-14 17:02:18
创建触发器功能是psql“语法错误在或接近”CREATE“”(Creating Trigger function is psql “syntax error at or near ”CREATE“”)

这是我的postgreSQL代码

CREATE FUNCTION connectedExhibitionFunction() RETURNS trigger AS $$ BEGIN IF (SELECT COUNT("exName") FROM Exhibitions WHERE NEW."exName" = "exName") > 0 THEN IF (SELECT Count(doorLoc1) FROM Doors, ExhibitionLocations WHERE (dorLoc1=NEW.elLocation AND dorLoc2=elLocations) OR (dorLoc2=NEW.elLocation AND dorLoc1=elLocations) > 0 THEN RAISE EXCEPTION 'You can't have the exhibition there, the same exhibition is in an unconnected room'; END IF; END IF; END; $$ LANGUAGE plpgsql; CREATE TRIGGER connectedExhibitionTrigger BEFORE INSERT ON ExhibitionsLocations EXECUTE PROCEDURE connectedExhibitionFunction();

这就是我得到的错误

psql:file.txt:62: ERROR: syntax error at or near "CREATE" LINE 8: CREATE FUNCTION connectedExhibitionFunction() ^ psql:file.txt:67: ERROR: current transaction is aborted, commands ignored until end of transaction block

我似乎无法弄清楚错误,任何人都可以在这里找到任何东西吗?

Here is my postgreSQL code

CREATE FUNCTION connectedExhibitionFunction() RETURNS trigger AS $$ BEGIN IF (SELECT COUNT("exName") FROM Exhibitions WHERE NEW."exName" = "exName") > 0 THEN IF (SELECT Count(doorLoc1) FROM Doors, ExhibitionLocations WHERE (dorLoc1=NEW.elLocation AND dorLoc2=elLocations) OR (dorLoc2=NEW.elLocation AND dorLoc1=elLocations) > 0 THEN RAISE EXCEPTION 'You can't have the exhibition there, the same exhibition is in an unconnected room'; END IF; END IF; END; $$ LANGUAGE plpgsql; CREATE TRIGGER connectedExhibitionTrigger BEFORE INSERT ON ExhibitionsLocations EXECUTE PROCEDURE connectedExhibitionFunction();

And this is the error I'm getting

psql:file.txt:62: ERROR: syntax error at or near "CREATE" LINE 8: CREATE FUNCTION connectedExhibitionFunction() ^ psql:file.txt:67: ERROR: current transaction is aborted, commands ignored until end of transaction block

I can't seem to figure out the error, can anybody spot anything here?

最满意答案

我猜你错过了选择“)”并且提出异常条款不能“不能”而你只能使用END而不是END IF。 据我所知,你的问题就是这些。

请试试这个。

IF (SELECT Count(doorLoc1) FROM Doors, ExhibitionLocations WHERE (dorLoc1=NEW.elLocation AND dorLoc2=elLocations) OR (dorLoc2=NEW.elLocation AND dorLoc1=elLocations)) > 0 THEN RAISE EXCEPTION 'You cant have the exhibition there, the same exhibition is in an unconnected room'; END

I guess you missed Select ")" and raise exception clause couldnt be "can't" And you can use just END instead of END IF. As far as I know your problem is these.

Try this please.

IF (SELECT Count(doorLoc1) FROM Doors, ExhibitionLocations WHERE (dorLoc1=NEW.elLocation AND dorLoc2=elLocations) OR (dorLoc2=NEW.elLocation AND dorLoc1=elLocations)) > 0 THEN RAISE EXCEPTION 'You cant have the exhibition there, the same exhibition is in an unconnected room'; END

更多推荐

本文发布于:2023-04-21 18:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/0016799372a93bfdcf16a79724e7c01d.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:触发器   语法错误   功能   psql   CREATE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!