<div dir="ltr">Dear All,<div><br></div><div>I am trying to use do loop to batch process some data.  See the code below:</div><div><br></div>Do $$<br><br>DECLARE<br>schema_name text := 'os_postcodes';<br>table_name text := 'code_point_britain_point';<br>tbo text :='os_postcodes.code_point_britain_point';<br>tb text :='code_point';<br>overlay_polygons text := 'admin_boundaries.jsna_warwickshire_polygon';<br>---max = select count(*) from overlay_polygons;<br>Counter integer :=0;<br><br>BEGIN<br>For counter IN 1..3 LOOP<br><br>execute format('select a.* into %s from %s a where st_intersects(a.geom, (select b.geom from %s b where mi_prinx = %s))=true;', tb, tbo, overlay_polygons,counter, tb);<br><br>counter :=counter + 1;<br>RAISE NOTICE 'Counter: %', counter;<br>END LOOP;<br>END; $$<br><div><br></div><div><br></div><div>My question is how to loop "select into a_table from" to create a series of new tables.<br></div><div><br></div><div>Can anyone help?</div><div><br></div><div>Regards,</div><div><br></div><div>Shao</div></div>