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 "NAME" with the unique name in ui00000bvbb.lad15nm:
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")
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:
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$