 			);',
 			table_name, grid_table_name
 		);
-		execute format(
-			'drop table %1$s;
-			alter table %1$s_intersected rename to %1$s;',
-			grid_table_name
-		);
+		execute 'drop table ' || grid_table_name;
 	end
 $$ language plpgsql;

		perform UpdateGeometrySRID(grid_table_name, 'the_geom', 900913);
		execute format('create index %s_index on %1$s using gist(the_geom)', grid_table_name);

		-- Create KK
		execute format(
			'create table %1$s_grid_intersected as
			select ST_Intersection(%1$s.the_geom, %2$s.the_geom) as geom
			from %1$s
			join %2$s
			on (

			(st_ymax(table_bbox) - st_ymin(table_bbox)) / (tile_size_meters :: float)
		);

		-- Create a table containing a grid with cells of length/width
		-- `tile_size_meters`, covering the entire extent of `table_name`.
		execute format(
			'create table %s as
			select *
