 BEGIN
 
 
-DROP TABLE IF EXISTS _campaign_indicator;
+		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;

			ON d.indicator_id = ci.indicator_id
			AND d.campaign_id = ci.campaign_id;

		DROP TABLE IF EXISTS _tmp_agg;
		CREATE TABLE _tmp_agg AS


		CREATE TEMP TABLE _to_agg AS

		WITH RECURSIVE region_tree AS
				(
				-- non-recursive term ( rows where the components aren't
				-- master_indicators in another calculation )

				SELECT
					rg.parent_region_id
					,rg.id as region_id
					,0 as lvl
				FROM region rg
			WHERE EXISTS (
				SELECT 1 FROM datapoint d
				WHERE d.region_id = rg.id
				AND d.cache_job_id = $1
			)

				UNION ALL

				-- recursive term --
				SELECT
					r_recurs.parent_region_id
					,rt.region_id
					,rt.lvl + 1
				FROM region AS r_recurs
				INNER JOIN region_tree AS rt
				ON (r_recurs.id = rt.parent_region_id)
			AND r_recurs.parent_region_id IS NOT NULL
				)

		SELECT DISTINCT
			d.id as datapoint_id
