title: How to loop through a string array and create multiple tables in Postgresql
body: <p>I would like to take a large table and break in up into smaller ones. I have the following code snippet which works by manually replacing <code>"NAME"</code> with the unique name in <code>ui00000bvbb.lad15nm</code>:</p>
  
  <pre><code>   CREATE TABLE "NAME" AS
     SELECT parcels_all_shapefile.* AS parcels
     FROM ui00000bvbb INNER JOIN parcels_all_shapefile ON ST_Intersects(ui00000bvbb.wkb_geometry, parcels_all_shapefile.wkb_geometry)
     WHERE ui00000bvbb.lad15nm = "NAME")
  </code></pre>
  
  <p>My question is how do I loop through a list of names and populate the above code? I have tried the following, but it doesn't work:</p>
  
  <pre><code>DO
  $do$
  DECLARE
     m   varchar[];
     arr varchar[] := array[['Barnet'],['Westminster']];
  BEGIN
     FOREACH m SLICE 1 IN ARRAY arr
     LOOP
         CREATE TABLE m AS
         SELECT parcels_all_shapefile.* AS parcels
         FROM ui00000bvbb INNER JOIN parcels_all_shapefile ON ST_Intersects(ui00000bvbb.wkb_geometry, parcels_all_shapefile.wkb_geometry)
         WHERE ui00000bvbb.lad15nm = m)
     END LOOP;
  END
  $do$
  </code></pre>