由于部分企业数据库从aws迁移到腾讯云,导致有一个定时任务(从详情表汇总数据到统计表中)错过了触发,所以这部分企业的数据需要触发重新刷一下,但是又有规定白天不允许上线,只能把定时任务的逻辑用存储过程(函数)实现一遍,通过这种方式把数据刷正确。下面是完整的存储过程示例:
--删除储存过程
--DROP FUNCTION f_sys_statlog_month(text,text,text)
--新建储存过程
CREATE OR REPLACE FUNCTION "public"."f_sys_statlog_month"(beginTime TEXT,endTime TEXT,monthTime TEXT)
RETURNS "pg_catalog"."void" AS $BODY$
DECLARE
c_record record;
BEGIN
delete from sys_statlog_month where statistics_time = monthTime;
for c_record in
with used_set as (
SELECT
b.user_id,
sum(case when b.client_type='1' THEN 1 else 0 end) as client_1,
sum(case when b.client_type='2' THEN 1 else 0 end) as client_2,
sum(case when b.client_type='4' THEN 1 else 0 end) as client_4,
sum(case when b.client_type='5' THEN 1 else 0 end) as client_5

文章描述了企业从AWS迁移至腾讯云后,因定时任务失误导致的数据问题。为避免在白天上线,作者提供了创建的存储过程示例,用于在指定时间段内,通过函数重新计算并插入数据到sys_statlog_month表中,以确保统计数据的准确性。
最低0.47元/天 解锁文章
1426

被折叠的 条评论
为什么被折叠?



