terezzy
terezzy

Reputation: 215

How to query recurrence rules in PostgreSQL?

I have a recurrence table that stores the iCalendar RFC 5545 Recurrence Rule string. Ex:

FREQ=MONTHLY;INTERVAL=2

Does anyone know of any postgres functions similar to do the following?

get_events_between(date,date)

Where It would just query the recurrence table and parse the rrule string.

Upvotes: 12

Views: 4376

Answers (1)

filiprem
filiprem

Reputation: 7144

In PostgreSQL, as of version 14, there is no built-in support for RFC-5545 Recurrence Rule format.

But there are some custom extensions out there.

  1. pg_rrule. When you install it, you should be able to query Ical schedules this way:
SELECT *
FROM unnest(
    get_occurrences(
        'FREQ=MONTHLY;INTERVAL=2'::rrule,
        now(),
        now() + '6 months'::interval
    )
);
  1. postgres-rrule

  2. You can get a Python RRULE parser (like dateutil) and embed it postgres using PL/Python.

Upvotes: 9

Related Questions