Created
December 13, 2016 16:06
-
-
Save rhysallister/3bd09b0df055b950d780b0aec430deea to your computer and use it in GitHub Desktop.
union all 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 | |
vv text; | |
hh record; | |
qry text; | |
qar text[]; | |
begin | |
qry = 'create table plus1.plus1 as '; | |
for hh in select * from pg_tables where schemaname = 'plus1' loop | |
qar = array_append(qar, ' SELECT "Name", description, geom from plus1.'|| quote_ident(hh.tablename)); | |
end loop; | |
raise notice '%', qry ||array_to_string(qar, e'\n UNION \n'::text); | |
end; | |
$$ language plpgsql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment