Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can implement the <a href="https://pypi.python.org/pypi/python-dateutil" rel="nofollow">python dateutil</a> rrule in postgresql.</p> <pre><code>CREATE OR REPLACE FUNCTION _pc_after( t_rule TEXT, t_after TIMESTAMP, inc BOOLEAN DEFAULT TRUE) RETURNS TIMESTAMP AS $$ from dateutil.rrule import * from dateutil.parser import * rule = rrulestr(t_rule) _after = parse(t_after) occurence = rule.before(_after, inc=False) return occurence $$ LANGUAGE 'plpythonu' VOLATILE; -- = simple before function = CREATE OR REPLACE FUNCTION _pc_before( t_rule TEXT, t_before TIMESTAMP, inc BOOLEAN DEFAULT TRUE) RETURNS TIMESTAMP AS $$ from dateutil.rrule import * from dateutil.parser import * _rule = rrulestr(t_rule) _before = parse(t_before) occurence = _rule.before(_before, inc=False) return occurence $$ LANGUAGE 'plpythonu' VOLATILE; -- = simple between function = CREATE OR REPLACE FUNCTION _pc_between( t_rule TEXT, t_after TIMESTAMP, t_before TIMESTAMP, inc BOOLEAN DEFAULT FALSE) RETURNS SETOF TIMESTAMP AS $$ from dateutil.rrule import * from dateutil.parser import * _rule = rrulestr(t_rule) _after = parse(t_after) _before = parse(t_before) occurences = _rule.between(_after, _before, inc) return occurences $$ LANGUAGE 'plpythonu' VOLATILE; CREATE OR REPLACE FUNCTION _pc_between( t_rule TEXT, t_after TIMESTAMP, t_before TIMESTAMP, inc BOOLEAN DEFAULT FALSE) RETURNS SETOF TIMESTAMP AS $$ from dateutil.rrule import * from dateutil.parser import * _rule = rrulestr(t_rule) _after = parse(t_after) _before = parse(t_before) occurences = _rule.between(_after, _before, inc) return occurences $$ LANGUAGE 'plpythonu' VOLATILE; </code></pre> <p>So :</p> <pre><code>SELECT _pc_between('DTSTART:20130102T090000 RRULE:FREQ=DAILY;INTERVAL=10;COUNT=25', cast('2013-01-01' as timestamp), cast('2013-05-31' as timestamp) ); </code></pre> <p>will return :</p> <pre><code>"2013-01-02 09:00:00" "2013-01-12 09:00:00" "2013-01-22 09:00:00" "2013-02-01 09:00:00" "2013-02-11 09:00:00" "2013-02-21 09:00:00" "2013-03-03 09:00:00" "2013-03-13 09:00:00" "2013-03-23 09:00:00" "2013-04-02 09:00:00" "2013-04-12 09:00:00" "2013-04-22 09:00:00" "2013-05-02 09:00:00" "2013-05-12 09:00:00" "2013-05-22 09:00:00" </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload