pgcalendar

为 PostgreSQL 提供循环日程、投影与例外处理的日历扩展

概览

扩展包名版本分类许可证语言
pgcalendar1.1.0TYPEMITSQL
ID扩展名BinLibLoadCreateTrustReloc模式
3890pgcalendarpgcalendar
相关扩展periods temporal_tables timeseries pg_cron

Deb/RPM recipes patch the stale upstream 1.1.0 control metadata (default_version/module_pathname).

版本

类型仓库版本PG 大版本包名依赖
EXTPIGSTY1.1.01817161514pgcalendar-
RPMPIGSTY1.1.01817161514pgcalendar_$v-
DEBPIGSTY1.1.01817161514postgresql-$v-pgcalendar-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d13.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
d13.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u22.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u22.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u24.x86_64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
u24.aarch64
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0
PIGSTY 1.1.0

构建

您可以使用 pig build 命令构建 pgcalendar 扩展的 RPM / DEB 包:

pig build pkg pgcalendar         # 构建 RPM / DEB 包

安装

您可以直接安装 pgcalendar 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install pgcalendar;          # 当前活跃 PG 版本安装
pig ext install -y pgcalendar -v 18  # PG 18
pig ext install -y pgcalendar -v 17  # PG 17
pig ext install -y pgcalendar -v 16  # PG 16
pig ext install -y pgcalendar -v 15  # PG 15
pig ext install -y pgcalendar -v 14  # PG 14
dnf install -y pgcalendar_18       # PG 18
dnf install -y pgcalendar_17       # PG 17
dnf install -y pgcalendar_16       # PG 16
dnf install -y pgcalendar_15       # PG 15
dnf install -y pgcalendar_14       # PG 14
apt install -y postgresql-18-pgcalendar   # PG 18
apt install -y postgresql-17-pgcalendar   # PG 17
apt install -y postgresql-16-pgcalendar   # PG 16
apt install -y postgresql-15-pgcalendar   # PG 15
apt install -y postgresql-14-pgcalendar   # PG 14

创建扩展

CREATE EXTENSION pgcalendar;

用法

语法:

CREATE EXTENSION pgcalendar;
INSERT INTO pgcalendar.events (name, description, category)
VALUES ('Daily Standup', 'Team daily standup meeting', 'meeting');
SELECT * FROM pgcalendar.get_event_projections(1, '2024-01-01'::date, '2024-01-07'::date);

来源:README

pgcalendar 是一个用于 PostgreSQL 的循环日历扩展。它建模事件、日程、例外和投影,并可在任意日期范围内生成日历发生实例。

数据模型

README 描述了四个核心概念:

  • events,表示会议或任务等逻辑对象
  • schedules,表示生成投影的非重叠循环定义
  • exceptions,表示单次发生的取消或修改
  • projections,表示实际生成出来的日历发生实例

快速开始

创建事件:

INSERT INTO pgcalendar.events (name, description, category)
VALUES ('Daily Standup', 'Team daily standup meeting', 'meeting');

创建日程:

INSERT INTO pgcalendar.schedules (
    event_id, start_date, end_date, recurrence_type, recurrence_interval
) VALUES (
    1, '2024-01-01 09:00:00', '2024-01-07 23:59:59', 'daily', 1
);

获取投影:

SELECT * FROM pgcalendar.get_event_projections(
    1, '2024-01-01'::date, '2024-01-07'::date
);

循环类型

README 展示了以下日程示例:

  • 每日循环
  • 每周循环,带 recurrence_day_of_week
  • 每月循环,带 recurrence_day_of_month
  • 每年循环,带 recurrence_monthrecurrence_day_of_month

例外

例外可以取消或修改某次发生:

INSERT INTO pgcalendar.exceptions (
    schedule_id, exception_date, exception_type, notes
) VALUES (
    1, '2024-01-15', 'cancelled', 'Holiday - meeting cancelled'
);

也可以修改日期和时间。

函数与视图

README 文档中包括:

  • get_event_projections(event_id, start_date, end_date)
  • get_events_detailed(start_date, end_date)
  • transition_event_schedule(...)
  • check_schedule_overlap(event_id, start_date, end_date)
  • pgcalendar.event_calendar

其中 transition_event_schedule(...) 用于安全切换事件的日程配置,check_schedule_overlap(...) 用于验证新日程不会与现有日程冲突。


最后修改 2026-04-10: extension update (13b4540)