CREATE or replace FUNCTION billtesting() RETURNS trigger AS
$$
BEGIN
if (destination_number'^(?:[0-7] ?){6,14}[0-9]$' ~ digits and destination_number !~ '15487498')
then
insert into isp_cdr(destination_number,caller_id,duration,billsec)
values (destination_number,caller_id,duration,billsec);
UPDATE isp_cdr
SET nibble_total_billed = billsec * user_rate;
end if;
RETURN NEW;
END
$$
LANGUAGE plpgsql;
CREATE TRIGGER bill_testing_update
BEFORE UPDATE
ON isp_cdr
FOR EACH ROW
EXECUTE PROCEDURE billtesting();
这是测试的查询
insert into isp_cdr(destination_number,caller_id,duration,billsec)
values ('012687512123','123125641','43','35');
这是示例lcr表信息
digits user_rate
1 0.02
23 0.07
652 0.12
1123 0.28
87521 0.15
123161 0.54
9641231 1.20
65491641 0.89
this is the sample isp_cdr table information
destination_number caller_id duration billsec nibble_total_billed
123561231 1315142 67 58 0
使用此触发器程序我希望将数字与destination_number匹配,并使用user_rate进行计算 user_rate * billsec = nibble_total_billed
但是在插入测试查询之后,计算确实正常工作它在nibble_total_billed上没有显示任何结果我认为我的模式匹配部分有一些错误我需要将数字与destination_number匹配。