我写了以下触发器。
CREATE OR REPLACE FUNCTION tbl_scdr_insert_trigger() RETURNS TRIGGER AS $$
<< fk >>
DECLARE
rowcount int;
myrec RECORD;
BEGIN
EXECUTE 'UPDATE sc_'|| to_char(NEW.start_datetime, 'YYYY_MM') ||' SET a = a + ($1).a, b = b + ($1).b WHERE (e_id = ($1).e_id AND start_datetime = ($1).start_datetime AND c_id = ($1).c_id'
USING NEW;
GET DIAGNOSTICS rowcount = ROW_COUNT;
RAISE NOTICE 'found %', rowcount;
IF not found THEN
RAISE NOTICE 'not found';
ELSIF found THEN
RAISE NOTICE 'found';
RETURN NULL;
END IF;
END;
$$
LANGUAGE plpgsql;
当 Ever Called 时,这始终返回零作为 Rowcount,因为尚未提交语句,并且即使存在 where 子句列的值相同的记录,Found 也始终为 False。