1
我創建了一個獎學金,數據庫和應用表觸發功能級檢查PostgreSQL的
applyid | studid | gpa | other | sch_id | date | sem | sy
---------+-----------+-----------+-------+----------+------------+-----+----
1 | 2010-0000 | 1.5 | | 1 | | |
2 | 2010-0001 | 1.5 | | 7 | 2014-03-13 | |
3 | 2010-0003 | | | 1 | 2014-03-13 | |
4 | 2010-0003 | | | 1 | 2014-03-13 | |
5 | 2010-0003 | | | 1 | 2014-03-13 | |
2308 | 2012-0004 | 1.5 | | 1 | 2014-03-19 | |
4593 | 2012-0004 | 1.5 | | 1 | 2014-03-19 | |
4596 | 2012-0004 | 1.5 | | 1 | 2014-03-19 | |
4597 | 2012-0004 | 1.5 | | 1 | 2014-03-19 | |
(9 rows)
和目前的工作來檢查,如果某個學生有兩種INC,DRP,5.00的等級這個觸發功能。
CREATE FUNCTION fail_check() RETURNS TRIGGER AS $$
DECLARE
one RECORD;
two RECORD;
BEGIN
SELECT * INTO one FROM grade, registration;
IF (SELECT COUNT(g.grade)::int
FROM grade g
INNER JOIN registration r ON r.grade_id = g.grade_id
WHERE g.grade IN ('INC', 'DRP', '5.00')
AND studid=new.studid) <= 1
THEN
SELECT studid, gpa, sch_name INTO two
FROM apply WHERE studid=new.studid;
INSERT INTO apply(studid, gpa, sch_name)
VALUES (new.studid, new.gpa, new.sch_name);
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER fail
BEFORE INSERT ON apply
FOR EACH ROW
EXECUTE PROCEDURE fail_check();
但是當我進入這個:
INSERT INTO apply(studid, gpa, sch_name)
VALUES ('2012-0004', '1.5', 1);
以 「2012-0004」 的學生證學生有INC DRP和5.00的成績。 SELECT
查詢完美地工作正常,並返回值3.由於3大於1,這是 聲明相反,我期望有一個錯誤,說不能插入,因爲「學生「擁有超過1級的INC,DRP,5.00。
而是我得到這個錯誤:
ERROR: stack depth limit exceeded
HINT: Increase the configuration parameter "max_stack_depth" (currently 2048kB), after ensuring the platform's stack depth limit is adequate.
CONTEXT: SQL statement "SELECT (SELECT COUNT(g.grade)
FROM grade g
INNER JOIN registration r ON r.grade_id = g.grade_id
WHERE g.grade IN ('INC', 'DRP', '5.00') AND studid=new.studid) <= 1" PL/pgSQL function fail_check() line 12 at IF SQL statement "INSERT INTO apply(studid, gpa, sch_name) VALUES (new.studid, new.gpa, new.sch_name)" PL/pgSQL function fail_check() line 21 at SQL statement SQL statement "INSERT INTO apply(studid, gpa, sch_name) VALUES (new.studid, new.gpa, new.sch_name)"
哪兒我去錯了?這個max_stack_depth究竟意味着什麼?我的代碼哪部分導致了這個max_stack_depth錯誤?
目前使用PostgreSQL 9.3.2
哦它現在可以工作。我改變了一切,刪除了'INSERT',你是對的,我發佈的觸發器沒有做任何有用的事情。謝謝! – oshixun