将一个 table 的汇总数据插入另一个 table

INSERT summary data of one table into another table

我正在尝试根据另一个 table 创建摘要 table。我有 table a,我希望 table b 成为每月 table a 状态的记录。

所以每个月我都希望能够安排一项工作来计算 a 中出现了多少条记录,并将该数字放入 table b

我什至不知道从哪里开始。

b 可能看起来像这样:

CREATE TABLE b (
  ts   timestamptz(0) PRIMARY KEY
, a_ct bigint NOT NULL
);

然后运行您方便的时候查询:

INSERT INTO b (ts, a_ct)
SELECT now(), count(*) FROM a;