Skip to content

Instantly share code, notes, and snippets.

@marinbek
Created June 2, 2014 09:46
Show Gist options
  • Save marinbek/c6357619ead29c25144a to your computer and use it in GitHub Desktop.
Save marinbek/c6357619ead29c25144a to your computer and use it in GitHub Desktop.
Import all tables from one schema to another schema - Redshift
SELECT 'drop table '||n.nspname ||'.'|| c.relname||' CASCADE;' as "Name"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','S','')
AND n.nspname = 'destination_schema';
SELECT 'create table '||n.nspname ||'.'|| c.relname||' as select * from source_schema.' || c.relname||';' as "Name"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','v','S','')
AND n.nspname = 'destination_schema';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment