 			);',
 			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;

create or replace function mz_CreateGrid(
	nrow integer,
	ncol integer,

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

		-- Intersect the gridded cells with the polygons in `table_name`,
		-- storing the now-tiled polygons in `${table_name}_tiles`.
		execute format(
			'create table %1$s_tiles as
			select
				row::text || ''-'' || col::text as gid,
				st_Intersection(%1$s.the_geom, %2$s.the_geom) as geom
			from %1$s
			join %2$s
			on (
