 			AND r_recurs.parent_region_id IS NOT NULL
 		    )
 
-		SELECT
-			d.id as datapoint_id, d.region_id, d.campaign_id, d.indicator_id, d,value, rt.parent_region_id
+		SELECT DISTINCT
+			d.id as datapoint_id
+			,d.indicator_id
+			,d.campaign_id
+			,d.region_id
+			,d.value
+			,rt.parent_region_id
 		FROM region_tree rt
 		INNER JOIN region r
 		ON r.parent_region_id = rt.parent_region_id

BEGIN


		DROP TABLE IF EXISTS _campaign_indicator;
		CREATE TABLE _campaign_indicator AS
		SELECT DISTINCT campaign_id, indicator_id FROM datapoint d
		WHERE d.cache_job_id = $1;

		DROP TABLE IF EXISTS _to_agg;
		CREATE TABLE _to_agg AS

		WITH RECURSIVE region_tree AS
		    (

			,d.indicator_id
			,SUM(d.value) as value
		FROM _to_agg d
		WHERE NOT EXISTS (
			SELECT 1 FROM _to_agg ta
			WHERE d.parent_region_id = ta.region_id
			AND d.campaign_id = ta.campaign_id
			AND d.indicator_id = ta.indicator_id
		)
 		GROUP BY d.parent_region_id, d.campaign_id, d.indicator_id;

		CREATE UNIQUE INDEX rc_agg_ix ON _tmp_agg(region_id,campaign_id,indicator_id);
