\set ON_ERROR_STOP

create or replace view null_inputs as
select sin.id as id,
       (sin.sin is null or sin.sin) and 
       (nin.nin is null or nin.nin) and 
       (oin.oin is null or oin.oin) as no_null_inputs
from (select id from executions) as ex
left join (select id,every(value is not null) as sin from execution_string_inputs group by id) as sin on ex.id = sin.id
left join (select id,every(value is not null) as nin from execution_number_inputs group by id) as nin on ex.id = nin.id
left join (select id,every(value is not null) as oin from execution_object_inputs group by id) as oin on ex.id = oin.id;

create or replace view runnable as
select ex.id as id,
       not(is_future(ex.id)) as not_future,
       ex.status = 'waiting' as is_waiting,
       pr.script != '' as nonempty_script,
       ni.no_null_inputs as no_null_inputs
from executions as ex
left join programs as pr on ex.program = pr.id
left join null_inputs as ni on ex.id = ni.id;