小编jpp*_*pp1的帖子

在 Postgres 触发器函数中的异常调用之前执行操作

Postgres 8.4 在这里。想象一下来自 Postgres doc 的这个代码片段

CREATE FUNCTION emp_stamp() RETURNS trigger AS $emp_stamp$
BEGIN
    -- Check that empname and salary are given
    IF NEW.empname IS NULL THEN
        RAISE EXCEPTION 'empname cannot be null';
    END IF;
    IF NEW.salary IS NULL THEN
        RAISE EXCEPTION '% cannot have null salary', NEW.empname;
    END IF;

    -- Who works for us when she must pay for it?
    IF NEW.salary < 0 THEN
        RAISE EXCEPTION '% cannot have a negative salary', NEW.empname;
    END IF;

    -- …
Run Code Online (Sandbox Code Playgroud)

postgresql triggers exception plpgsql

6
推荐指数
1
解决办法
5773
查看次数

标签 统计

exception ×1

plpgsql ×1

postgresql ×1

triggers ×1