Script to import a table to another schema in PostgreSQL
- Written by: ilmarkerm
- Category: Blog entry
- Published: February 9, 2011
Tested with Centos 5 and PostgreSQL 8.4.
Sadly PostgreSQL does not have remap_schema parameter in its data import tool pg_restore, so importing tables to another schema in destination database is a little bit tricky.
Here is a Bash script I use to connect to the source database over SSH tunnel, export two tables (srv.stat_export and disp.trip) and then import them to the destination database under schema etl.
You can also dump the tables (pg_dump -t ..) , import them (psql -f) and change the table's schema "alter tabel X set schema destination_schemaname;"
select 'alter table "' || tablename || '" set schema "DESTINATION_SCHEMA";' from pg_tables where schemaname='current_tables_schema';
=======
datacoffee