If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > transfer between schemas

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-27-11, 02:53
100ka 100ka is offline
Registered User
 
Join Date: Jul 2011
Posts: 1
transfer between schemas

Hello guys, I’m a new in this forum and I’d like to excuse me for my poor English. There is a difficult case for me to solve so I’d like to ask you for advice. The situation is as follow:
We have a database with many schemas and a role for each schema. Every user works with own role and schema. All the schema contains same objects – tables, indexes, constraints, views, functions etc. There is also one “default” schema called “template_schema” which is empty and is used for template for creating of new schemas. I have to automate the creation of new schemas and when a new user is registered new empty schema has to be created for him. I have a function which is executed on user registration and creates new empty schema and role for this schema, but cannot fill this new schema with objects from template schema. I have to do this with postgresql functions because I don’t have access to shell – pg_dump, psql.. Is there any suggestion how to do that? Thanks in advance. I hope I was clear and excuse me for my English.
Reply With Quote
  #2 (permalink)  
Old 07-27-11, 19:25
someidiot someidiot is offline
Registered User
 
Join Date: Mar 2011
Posts: 27
First off, sounds like a perfect use for template databases (not schemas!). You can easily create a new database as a copy of an existing template database with a single command.

You can copy a table structure easily (see sql - Copy a table (including indexes) in postgres - Stack Overflow). But to do that for a list of tables you will need to either hardcode the table names or put it in a pgsql loop.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On