Skip to content

Instantly share code, notes, and snippets.

@vskrachkov
Created March 24, 2017 08:53
Show Gist options
  • Save vskrachkov/a0828e24a6342f151dac00a19d40dfbf to your computer and use it in GitHub Desktop.
Save vskrachkov/a0828e24a6342f151dac00a19d40dfbf to your computer and use it in GitHub Desktop.
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