Created
March 24, 2017 08:53
-
-
Save vskrachkov/a0828e24a6342f151dac00a19d40dfbf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
select t.table_schema, t.table_name, | |
'TRUNCATE public.' || t.table_name || ' CASCADE;', 'insert into public.' | |
|| t.table_name || '(' || string_agg(c.column_name, ',') || ') select ' || string_agg(c.column_name, ',') || ' from ' | |
|| 'main.' || substring(t.table_name from 6) || ';' | |
from information_schema.columns c | |
join information_schema.tables t on t.table_name = c.table_name and t.table_schema = 'public' | |
where t.table_schema in ('public') and t.table_type = 'BASE TABLE' | |
GROUP BY t.table_schema, t.table_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment