Select records with repeatable datetime PostgreSQL -


i facing problem calendar.

i have extract records (events) (via select) with: 1. specific date, or 2. repeatable date

the problem normal calendar displays entire month (or specific range of time), possible select record subset generated subquery (and compare date fragments), i.e.:

select (generate_series('2012-06-29 00:00:00',                         '2012-07-03 00:00:00',                          '5 minutes'::interval))::timestamp; 

i have build view of calendar infinite list of events, can scroll down. have display events one-by-one. when select events (i.e. 2012-06-29 00:00:00 2012-10-29 00:00:00), statement not consider record date 2012-10-30 00:00:00, not expected.

how can select multiple, non-continuous dates?

the database schema:

create table "public"."events" ( "id" int4 default nextval('events_id_seq'::regclass) not null, "date" timestamp(6), "date_repeat_interval" interval(6), "date_repeat_start" timestamp(6), "date_repeat_stop" timestamp(6), "event_name" varchar(255) not null ) (oids=false); 

insert regular events on specific date:

insert "public"."events" values ('1', '2013-04-18 14:04:39', null, null, null, 'regular 1'); insert "public"."events" values ('2', '2013-04-19 14:04:50', null, null, null, 'regular 2'); 

and insert events interval 1 , 2 days , specified repetition , date:

insert "public"."events" values ('3', null, '1 day', '2013-04-16 14:05:26', '2013-04-19 14:05:31', 'repeatable 1'); insert "public"."events" values ('4', null, '2 days', '2013-04-17 14:05:49', '2013-06-15 14:05:53', 'repeatable 2'); 

question:

how query database events in range: infinity limit 10. occurs in order of occurence including multiple occurence repeatable events.

you can recursive cte. note need add limits or happily repeat infinity.

with recursive event_calendar (     select id, coalesce("date", date_repeat_start) e_date, event_name, 0 level       events      union     select e.id, ec.e_date + date_repeat_interval, ec.event_name, ec.level + 1       events e       join event_calendar ec on e.id = ec.id      ec.level <= 10 , e.date_repeat_start not null             , e.date_repeat_stop >= ec.e_date + date_repeat_interval ) select * event_calendar order e_date; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -