 UPDATE orig_consumption_znes.lak_consumption_per_district
 	SET consumption_per_area_tertiary_sector = elec_consumption_tertiary_sector/nullif(area_tertiary_sector,0);
 
-UPDATE orig_consumption_znes.lak_consumption_per_district
-	SET consumption_per_area_industry = elec_consumption_industry/nullif(area_industry,0);
 
 
 ---------- ---------- ----------

---------- ---------- ----------


-- Calculate the industrial area per district 
SELECT sum(sector_area_industrial), substr(nuts,1,5) 
	INTO orig_consumption_znes.temp_table
	FROM model_draft.ego_demand_loadarea
	GROUP BY substr(nuts,1,5);

UPDATE orig_consumption_znes.lak_consumption_per_district a
	SET area_industry = sum
	FROM orig_consumption_znes.temp_table b
	WHERE b.substr = substr(a.eu_code,1,5);

DROP TABLE orig_consumption_znes.temp_table;

-- Calculate the retail area per district

SELECT sum(sector_area_retail), substr(nuts,1,5) 
	INTO orig_consumption_znes.temp_table
	FROM model_draft.ego_demand_loadarea
	GROUP BY substr(nuts,1,5);

UPDATE orig_consumption_znes.lak_consumption_per_district a
	SET area_retail = sum
	FROM orig_consumption_znes.temp_table b
	WHERE b.substr = substr(a.eu_code,1,5);

DROP TABLE orig_consumption_znes.temp_table;

-- Calculate the agricultural area per district

SELECT sum(sector_area_agricultural), substr(nuts,1,5) 
	INTO orig_consumption_znes.temp_table
	FROM model_draft.ego_demand_loadarea
	GROUP BY substr(nuts,1,5);

UPDATE orig_consumption_znes.lak_consumption_per_district a
	SET area_agriculture = sum
	FROM orig_consumption_znes.temp_table b
	WHERE b.substr = substr(a.eu_code,1,5);

DROP TABLE orig_consumption_znes.temp_table;

-- Calculate area of tertiary sector by adding agricultural and retail area up


-- 
-- -- "Grant oeuser"   (OK!) -> 100ms =0
-- GRANT ALL ON TABLE 	model_draft.ego_demand_loadarea_spf TO oeuser WITH GRANT OPTION;
-- ALTER TABLE		model_draft.ego_demand_loadarea_spf OWNER TO oeuser;
