# Unwinds the division of some nodes into embedded generation and 'true' load, for convenience.
#
# You must first populate o_raw_node_ir.

USE tpm3;


CREATE TABLE o_raw_node_ir_old_style AS
SELECT runtype, record_date, tp, CASE WHEN SUBSTRING(node,8,1)='e' THEN SUBSTRING(node,1,7) ELSE node END AS node, SUM(generation) AS generation, SUM(demand) AS net_demand
FROM o_raw_node_ir
WHERE runtype='base3k'
GROUP BY runtype, record_date, tp, CASE WHEN SUBSTRING(node,8,1)='e' THEN SUBSTRING(node,1,7) ELSE node END;

CREATE INDEX idx ON o_raw_node_ir_old_style (runtype, node, record_date, tp);
