-- ===========================================================================
-- Creating Table ============================================================
-- ===========================================================================
create table eventtest
(
Id int,
dates date,
hours int,
minutes int
)engine=columnstore;

-- ===========================================================================
-- Creating Event ============ This doesn't work =============================
-- ===========================================================================
create event testing
on schedule every 1 minute
do
insert into eventtest(id,dates,hours,minutes)
select 1 as id,t.dates,t.hours,t.minutes
from
(
select current_date as dates,10 as hours, 0 as minutes union
select adddate(current_date,1) as dates,10 as hours, 0 as minutes union
select adddate(current_date,2) as dates,10 as hours, 0 as minutes union
select adddate(current_date,3) as dates,10 as hours, 0 as minutes union
select adddate(current_date,4) as dates,10 as hours, 0 as minutes union
select adddate(current_date,5) as dates,10 as hours, 0 as minutes union
select adddate(current_date,6) as dates,10 as hours, 0 as minutes union
select adddate(current_date,7) as dates,10 as hours, 0 as minutes union
select adddate(current_date,8) as dates,10 as hours, 0 as minutes
) t left join
dataset.eventtest et on cast(t.dates as date) = cast(et.dates as date) and t.hours = et.hours
where et.dates is null
;

-- ============ THIS WORKS =====================================

alter event testing
on schedule every 1 minute
do
insert into eventtest(id,dates,hours,minutes)
select 1 as id,current_date,hour(current_timestamp),minute(current_timestamp);

-- ====================== Truncating the table =====================================
truncate table eventtest;
-- =================================================================================


-- ============ THIS DOESN'T WORK =====================================

insert into eventtest(id,dates) values (1,'2017-12-19')

alter event testing
on schedule every 1 minute
do
insert into eventtest(id,dates)
select 1 as id,adddate(max(dates),1) as dates from eventtest;

select * from eventtest; -- Still empty

