user1235288
user1235288

Reputation: 75

PostgreSQL merge two schemas with identical tables

I've got some data from one year but it is split into two schema. How can I put them together in one schema so that I can process it with MATLAB.

Upvotes: 1

Views: 3628

Answers (1)

A.H.
A.H.

Reputation: 66213

If your table names in both schemas are unique you can use in the psql shell

ALTER TABLE old_schema.table_name SET SCHEMA new_Schema;

On the other hand I would be surprised when Matlab did not allow you to access any schema. Did you try to access your tables with old_schema.table1 and new_schema.table2? In that case you wouldn't have to change the database.

Edit

If you have quite a handful tables, you have to issue the above command for each table. There is no way around this. But a little help: You can compute the commands and execute the results by hand. Computation is done with this:

select 'ALTER TABLE '||table_schema||'.'||table_name||' SET SCHEMA new_schema' 
   from information_schema.tables 
   where table_type = 'BASE TABLE' and table_schema = 'old_schema';

Upvotes: 2

Related Questions