 ALTER TABLE public.cd_meter_ids_for_houses_with_pv_with_locations OWNER TO eileen;
 
 --
--- Name: readings_with_meter_id_unfiltered; Type: VIEW; Schema: public; Owner: daniel
---
-
-CREATE VIEW readings_with_meter_id_unfiltered AS
+-- Name: readings_with_meter_data_id_unfiltered; Type: VIEW; Schema: public; Owner: daniel
+--
+
+CREATE VIEW readings_with_meter_data_id_unfiltered AS
     SELECT "Interval".end_time, "MeterData".meter_name, "Reading".channel, "Reading".raw_value, "Reading".value, "Reading".uom, "IntervalReadData".start_time, "IntervalReadData".end_time AS ird_end_time, "MeterData".meter_data_id FROM ((("MeterData" JOIN "IntervalReadData" ON (("MeterData".meter_data_id = "IntervalReadData".meter_data_id))) JOIN "Interval" ON (("IntervalReadData".interval_read_data_id = "Interval".interval_read_data_id))) JOIN "Reading" ON (("Interval".interval_id = "Reading".interval_id)));
 
 
-ALTER TABLE public.readings_with_meter_id_unfiltered OWNER TO daniel;
-
---
--- Name: VIEW readings_with_meter_id_unfiltered; Type: COMMENT; Schema: public; Owner: daniel
---
-
-COMMENT ON VIEW readings_with_meter_id_unfiltered IS 'Readings along with their end times by meter. @author Daniel Zhang (張道博)';
+ALTER TABLE public.readings_with_meter_data_id_unfiltered OWNER TO daniel;
+
+--
+-- Name: VIEW readings_with_meter_data_id_unfiltered; Type: COMMENT; Schema: public; Owner: daniel
+--
+
+COMMENT ON VIEW readings_with_meter_data_id_unfiltered IS 'Readings along with their end times by meter. @author Daniel Zhang (張道博)';
 
 
 --

--

COMMENT ON VIEW deprecated_dz_energy_voltages_for_houses_without_pv IS 'Return energy and voltages for houses without PV. @author Daniel Zhang (張道博)';


--



--
-- Name: readings_by_meter_location_history; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW readings_by_meter_location_history AS
    SELECT "MeterLocationHistory".meter_name, "MeterLocationHistory".service_point_id, "MeterLocationHistory".service_point_latitude, "MeterLocationHistory".service_point_longitude, "MeterLocationHistory".location, "MeterLocationHistory".address, "MeterLocationHistory".latitude, "MeterLocationHistory".longitude, "MeterLocationHistory".installed, "MeterLocationHistory".uninstalled, "Reading".channel, "Reading".raw_value, "Reading".value, "Reading".uom, "Interval".end_time, "MeterData".meter_data_id FROM (((("MeterLocationHistory" JOIN "MeterData" ON ((("MeterLocationHistory".meter_name)::bpchar = "MeterData".meter_name))) JOIN "IntervalReadData" ON (("MeterData".meter_data_id = "IntervalReadData".meter_data_id))) JOIN "Interval" ON (("IntervalReadData".interval_read_data_id = "Interval".interval_read_data_id))) JOIN "Reading" ON (((("Interval".interval_id = "Reading".interval_id) AND ("Interval".end_time >= "MeterLocationHistory".installed)) AND CASE WHEN ("MeterLocationHistory".uninstalled IS NULL) THEN true ELSE ("Interval".end_time < "MeterLocationHistory".uninstalled) END)));


ALTER TABLE public.readings_by_meter_location_history OWNER TO postgres;

--
-- Name: dz_energy_voltages_for_houses_without_pv; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW dz_energy_voltages_for_houses_without_pv AS
    SELECT readings_by_meter_location_history_2.meter_name, readings_by_meter_location_history_2.end_time, max(CASE WHEN (readings_by_meter_location_history_2.channel = (1)::smallint) THEN readings_by_meter_location_history_2.value ELSE NULL::real END) AS "Energy to House kwH", zero_to_null(max(CASE WHEN (readings_by_meter_location_history_2.channel = (4)::smallint) THEN readings_by_meter_location_history_2.value ELSE NULL::real END)) AS "Voltage", max(readings_by_meter_location_history_2.service_point_longitude) AS service_pt_longitude, max(readings_by_meter_location_history_2.service_point_latitude) AS service_pt_latitude, max((readings_by_meter_location_history_2.address)::text) AS address FROM (meter_ids_for_houses_without_pv JOIN readings_by_meter_location_history readings_by_meter_location_history_2 ON (((meter_ids_for_houses_without_pv.device_util_id)::text = (readings_by_meter_location_history_2.meter_name)::text))) WHERE ((readings_by_meter_location_history_2.channel = (1)::smallint) OR (readings_by_meter_location_history_2.channel = (4)::smallint)) GROUP BY readings_by_meter_location_history_2.meter_name, readings_by_meter_location_history_2.end_time;


ALTER TABLE public.dz_energy_voltages_for_houses_without_pv OWNER TO postgres;
