Below is a dummy test query that correctly creates a text version of a SQL query I seek to execute
select string_agg(format($q$SELECT c1,c2 FROM %I.parcel t
JOIN bounds b
ON 1=1
$q$, shm), e'UNION\n') as sql
FROM unnest(array['a','b','c']) as shm
this outputs
SELECT C1,C2 FROM a.parcel t
JOIN bounds b
ON 1=1
UNION
SELECT C1,C2 FROM b.parcel t
JOIN bounds b
ON 1=1
UNION
SELECT C1,C2 FROM c.parcel t
JOIN bounds b
ON 1=1
which is correct. What I want to do is actually run the above query. I tried un-nesting it but that did not work. Again this is test data so the contents of the query do not matter
I know I can do this
DO
$do$
BEGIN
execute string_agg(format($q$SELECT c1,c2 FROM %I.parcel t
JOIN bounds b
ON 1=1
$q$, shm), e'UNION\n') as sql
FROM unnest(array['a','b','c']) as shm
END
$do$;
but its not actually running the SQL text