  	,CAST(ovs.settlementgps_longitude AS FLOAT)
  	,2 as region_type_id --settlement
  	,1 as office_id -- nigeria
- 	,REPLACE(settlementname,' ' ,'-') as region_slug
+ 	,REPLACE(settlementname,' ' ,'-') AS region_slug
  	,now()
  	,s.id
  	,CAST(0 as BOOLEAN)


RETURN QUERY

SELECT id
FROM source_region sr
LIMIT 1;


-- DELETE ACTUAL DUPES.. IE NOT REGIONS WITH SAME NAME WITH DIFF PARENT--
DELETE
FROM _odk_settlements
WHERE settlementcode in
(
	SELECT
		settlementcode
		--,count(*) AS C
	FROM _odk_settlements
	GROUP BY settlementcode HAVING count(*) > 1
);

-- SELECT region_code,count(1) FROM _odk_settlements
-- GROUP BY region_code HAVING COUNT(1) > 1


DELETE
FROM _odk_settlements
WHERE REPLACE(settlementname,' ' ,'-') IN
(
	SELECT
		REPLACE(settlementname,' ' ,'-')
		--,count(*) AS C
	FROM _odk_settlements
	GROUP BY REPLACE(settlementname,' ' ,'-') HAVING count(*) > 1
);


