我有一个需要在电话号码上进行匹配的触发器,到目前为止这有效,但似乎没有优化:
IF NEW.caller LIKE '44%' THEN
caller_tmp := SUBSTRING(NEW.caller FROM 3);
IF caller_tmp ~ '^[0-9]+$' THEN
NEW.caller_name := (SELECT phonenumber_name FROM phonebook WHERE caller_tmp::BIGINT LIMIT 1);
END IF;
ELSEIF NEW.caller LIKE '+44%' THEN
caller_tmp := SUBSTRING(NEW.caller FROM 4);
IF caller_tmp ~ '^[0-9]+$' THEN
NEW.caller_name := (SELECT phonenumber_name FROM phonebook WHERE caller_tmp::BIGINT LIMIT 1);
END IF;
ELSEIF NEW.caller LIKE '0044%' THEN
caller_tmp := SUBSTRING(NEW.caller FROM 5);
IF caller_tmp ~ '^[0-9]+$' THEN
NEW.caller_name := (SELECT phonenumber_name FROM phonebook WHERE caller_tmp::BIGINT LIMIT 1);
END IF;
END IF;
我需要检查电话号码是否来自英国,前面包含44,+ 44或0044。如果是,我需要检查它是否是一个有效的整数,然后进行匹配。
这可以针对更好的性能进行优化吗?