【无标题】

Postgre 存储过程编写:

create or replace procedure a.lockUser(int,int)
language plpgsql
as $$
    begin
    
        update a.t_user set lockout =true from ( 
			SELECT distinct username lockuser
			from a.t_log 
			where 
			(start_time between  date_trunc('minute', (to_timestamp( $1 ))) - INTERVAL '1 minute' AND (to_timestamp( $1 )))
			and username is not null
			GROUP BY username
			having count(1) > $2
        ) as lu
		where username = lu.lockuser;
        
        commit;
    end;
$$

参数1:时间戳
Note:生成时间戳,select floor(extract(epoch from now()));
参数2:限制数

call a.lockUser(floor(extract(epoch from now()))::int,5)

使用pg_cron调用。
一分钟一次。

SELECT cron.schedule('* * * * *', $$ call a.lockUser(floor(extract(epoch from now()))::int,5)$$);
上一篇:用Taro写一个微信小程序——Taro3路由传参


下一篇:【Python入门篇】开发工具的安装和配置(全了)