首页 > 解决方案 > Postgresql 每日插入

问题描述

我正在尝试创建每天运行的库存日志

基本上在我的日志表上,我想总结每天有多少单位有状态 1、有多少单位有状态 2 等等

有没有办法填写我的日志表而不必每天手动完成?

我的日志表是 id serial, date date, count_of_status1 integer, count_of_status2 integer

我的插入查询将是

insert into logtable(date, count_of_status1, count_of_status2)
select now(),  count(*) filter (where status =1), count(*) filter (where status = 2)
from mytable

如何使这个插入每天以自动形式而不是手动完成?

标签: sqlpostgresql

解决方案


用于crontab通过 运行该脚本psql

最简单的解决方案通常是最可靠的解决方案。但请确保crontab报告错误而不是忽略它们。


推荐阅读