pgcalendar
为 PostgreSQL 提供循环日程、投影与例外处理的日历扩展
概览
| 扩展包名 | 版本 | 分类 | 许可证 | 语言 |
|---|---|---|---|---|
pgcalendar | 1.1.0 | TYPE | MIT | SQL |
| ID | 扩展名 | Bin | Lib | Load | Create | Trust | Reloc | 模式 |
|---|---|---|---|---|---|---|---|---|
| 3890 | pgcalendar | 否 | 否 | 否 | 是 | 否 | 否 | pgcalendar |
| 相关扩展 | periods temporal_tables timeseries pg_cron |
|---|
Deb/RPM recipes patch the stale upstream 1.1.0 control metadata (default_version/module_pathname).
版本
| 类型 | 仓库 | 版本 | PG 大版本 | 包名 | 依赖 |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.1.0 | 1817161514 | pgcalendar | - |
| RPM | PIGSTY | 1.1.0 | 1817161514 | pgcalendar_$v | - |
| DEB | PIGSTY | 1.1.0 | 1817161514 | postgresql-$v-pgcalendar | - |
构建
您可以使用 pig build 命令构建 pgcalendar 扩展的 RPM / DEB 包:
pig build pkg pgcalendar # 构建 RPM / DEB 包
安装
您可以直接安装 pgcalendar 扩展包的预置二进制包,首先确保 PGDG 和 PIGSTY 仓库已经添加并启用:
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_month和recurrence_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(...) 用于验证新日程不会与现有日程冲突。