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
u26.x86_64
u26.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;

用法

来源:READMErepo

pgcalendar 是一个 PostgreSQL 循环日历扩展。上游 README 用四个核心对象来建模循环日程:eventsschedulesexceptions 和生成出来的 projections。

创建事件和日程

CREATE EXTENSION pgcalendar;

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
);

README 展示了 dailyweeklymonthlyyearly 四类循环,并会根据类型使用 recurrence_day_of_weekrecurrence_day_of_monthrecurrence_month 等额外列。

查询投影

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

SELECT * FROM pgcalendar.get_events_detailed(
    '2024-01-01'::date, '2024-01-31'::date
);

README 还把 pgcalendar.event_calendar 视图作为快速核验结果的入口。

例外与日程切换

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

SELECT pgcalendar.transition_event_schedule(
    p_event_id := 1,
    p_new_start_date := '2024-01-15 09:00:00',
    p_new_end_date := '2024-01-31 23:59:59',
    p_recurrence_type := 'weekly',
    p_recurrence_interval := 2,
    p_recurrence_day_of_week := 1,
    p_description := 'Changed to bi-weekly schedule'
);

如果需要在新增日程前确认日期范围不重叠,可以先调用 pgcalendar.check_schedule_overlap(...)

注意事项

目前上游唯一公开的用户文档就是 README。它已经给出了较完整的表结构和函数示例,但没有另外维护按版本划分的用户可见 SQL 变更说明。


最后修改 2026-05-01: update extension data (e399d22)