Last active
April 6, 2017 16:59
-
-
Save rhysallister/f68f11b5024728c19914f378533297f8 to your computer and use it in GitHub Desktop.
Bulk change ownership of foreign tables in a schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do | |
$$ | |
DECLARE | |
bret record; | |
fret text; | |
idx text; | |
BEGIN | |
fret := 'CREATE MATERIALIZED VIEW arcfm_test_.%I as select * from arcfm_test_.%I;'; | |
idx := 'CREATE INDEX ON arcfm_test_.%I USING gist (geom);'; | |
FOR bret IN | |
select * from pg_catalog.pg_class | |
join pg_catalog.pg_foreign_table on oid = ftrelid | |
where ftserver = 376514 order by 1 | |
LOOP | |
IF split_part(bret.relname,'.',2) ~* '[0-9]{2,3}$' THEN | |
RAISE NOTICE 'Skipped Delta table: %', bret.relname; | |
CONTINUE; | |
END IF; | |
RAISE NOTICE '%', bret.relname; | |
EXECUTE format(fret,bret.relname ||'_mv',bret.relname); | |
EXECUTE format(idx,bret.relname ||'_mv'); | |
END LOOP; | |
END; | |
$$ | |
language plpgsql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment