Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 942
terezzy Avatar asked Aug 27 '15 20:08

terezzy


People also ask

Can we use CTE in PostgreSQL?

In PostgreSQL, the CTE(Common Table Expression) is used as a temporary result set that the user can reference within another SQL statement like SELECT, INSERT, UPDATE or DELETE. CTEs are temporary in the sense that they only exist during the execution of the query.

How do I create a hierarchical query in PostgreSQL?

CONNECT BY, PRIOR and START WITH in Oracle In Oracle, the hierarchical query is defined using the two mandatory keywords i.e. CONNECT BY and START WITH. The hierarchy is built when the CONNECT BY defines the relationship between parent and child, the PRIOR keyword used with CONNECT by specifies the parent.

Can we use with clause in PostgreSQL?

You can use data-modifying statements (INSERT, UPDATE or DELETE) in WITH. This allows you to perform several different operations in the same query.

WHAT IS WITH clause in PostgreSQL?

WITH provides a way to write auxiliary statements for use in a larger query. These statements, which are often referred to as Common Table Expressions or CTE s, can be thought of as defining temporary tables that exist just for one query.


1 Answers

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

  2. postgres-rrule

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

like image 108
filiprem Avatar answered Sep 24 '22 16:09

filiprem