DROP FUNCTION merge_region(INT, INT);
CREATE FUNCTION merge_region(INT source, INT target) RETURNS INT AS $$
UPDATE structure SET cityid = target WHERE cityid = source;
UPDATE region SET parentid = target WHERE parentid = source;
-- object_region change
DELETE FROM data WHERE objectid = source;
DELETE FROM region WHERE id = source;
-- SELECT cast($1/10000 as text) || COALESCE('-' || lpad(cast(NULLIF($1/100 % 100,0) as text),2,'0') || COALESCE('-' || lpad(cast(NULLIF($1 

$$ LANGUAGE SQL RETURNS NULL ON NULL INPUT;


