CREATE OR REPLACE FUNCTION exec(text) returns text language plpgsql volatile AS $f$ BEGIN EXECUTE $1; RETURN $1; END; $f$; \o /dev/null SELECT exec('drop table if exists foo_'||g.i||'; create table foo_'||g.i||'(id int4);') FROM generate_series(1, 64) g(i); \o CHECKPOINT;