Quantcast
Channel: Planet PostgreSQL
Viewing all articles
Browse latest Browse all 9843

Pavel Golub: How to move data from one schema to another in Postgres?

$
0
0

I saw a question today :

I have PostpreSQL 9.1. In my database there are 2 schemas: public and test. How can I quickly move all objects and data from public to test?

Opps. I’m stuck with this issue for some time. I was thinking about dump and restore tricks, about direct changes to the pg_catalog schema etc. I even appeared on the IRC channel with this question.

There I had conversation with Jon SuckMojo Erdman, who’s first thought was dump way either. But then we have found a simple and elegant solution independently.

Assuming schema test is empty:

DROP SCHEMA test;

ALTER SCHEMA public RENAME TO test;

CREATE SCHEMA public;

Booyah!


Filed under: PostgreSQL Tagged: PostgreSQL, trick

Viewing all articles
Browse latest Browse all 9843

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>