 and max(mechvent) = 1
 order by icustay_id, ventnum;
 
-DROP TABLE ventsettings;
+DROP MATERIALIZED VIEW ventsettings;



-- First, create a temporary table to store relevant data from CHARTEVENTS.
DROP TABLE IF EXISTS ventsettings CASCADE;
CREATE TABLE ventsettings AS
select
  icustay_id, charttime
  -- case statement determining whether it is an instance of mech vent



--DROP MATERIALIZED VIEW IF EXISTS VENTDURATIONS CASCADE;
DROP MATERIALIZED VIEW IF EXISTS VENTDURATIONS CASCADE;
create MATERIALIZED VIEW ventdurations as
with vd0 as
(
  select
