使用 postgresql 触发
首先是我的代码:
CREATE FUNCTION unknown_Model ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
--checks if the product table has information pertaining to the new PC insertion
BEGIN
IF (SELECT COUNT(Product.model)
FROM Product
WHERE Product.model = NEW.model) = 0 THEN
INSERT INTO Product VALUES ('X', NEW.model, 'PC');
END IF;
RETURN NEW;
END
$$;
CREATE TRIGGER unknownModel
BEFORE INSERT OR UPDATE ON PC
FOR EACH ROW EXECUTE PROCEDURE unknown_Model();
我不断收到错误“控制到达触发过程结束而没有返回”。我看过互联网上的其他例子,它们与我的非常相似。知道为什么它看不到我的退货声明吗?
谢谢
First off here is my code:
CREATE FUNCTION unknown_Model ()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $
--checks if the product table has information pertaining to the new PC insertion
BEGIN
IF (SELECT COUNT(Product.model)
FROM Product
WHERE Product.model = NEW.model) = 0 THEN
INSERT INTO Product VALUES ('X', NEW.model, 'PC');
END IF;
RETURN NEW;
END
$;
CREATE TRIGGER unknownModel
BEFORE INSERT OR UPDATE ON PC
FOR EACH ROW EXECUTE PROCEDURE unknown_Model();
I keep getting the error "control reached end of trigger procedure without RETURN". I've looked at other examples on the internet and they are very similar to mine. Any idea why it is not seeing my return statement?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
将语言声明移到过程主体之后。据我所知,这不应该很重要,但是......好吧,尝试一下,看看是否有帮助。
分享并享受。
Try
i.e. move the language declaration after the procedure body. AFAIK this shouldn't matter, but...well, try it and see if it helps.
Share and enjoy.