 
 
 -- First, create a temporary table to store relevant data from CHARTEVENTS.
-DROP TABLE IF EXISTS ventsettings CASCADE;
-CREATE TABLE ventsettings AS
+DROP MATERIALIZED VIEW IF EXISTS ventsettings CASCADE;
+CREATE MATERIALIZED VIEW 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 TABLE IF EXISTS VENTDURATIONS CASCADE;
create table ventdurations as
with vd0 as
(
  select

and max(mechvent) = 1
order by icustay_id, ventnum;

DROP MATERIALIZED VIEW ventsettings;
