op.execute('update notifications set notification_type = (select cast(cast(template_type as text) as notification_type) from templates where templates.id= notifications.template_id)')
conn=op.get_bind()
del_sql="select n.id, results.* from (select 'failed' as stat_type, count(status) as count, notification_type, date(created_at) as day, service_id " \
"from notifications where status in ('temporary-failure', 'permanent-failure', 'technical-failure') group by service_id, notification_type, date(created_at) " \
"union select 'delivered' as stat_type, count(status) , notification_type, date(created_at) as day, service_id " \
"from notifications where status in ('delivered') group by service_id, notification_type, date(created_at)) as results, " \
"notification_statistics n " \
"where n.day = results.day and n.service_id = results.service_id order by results.day;"