473,395 Members | 1,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Transfer database tables to a schema

Folks,
I have a couple of databases that should really be schemas in the same
database. I tried to find suggestions on how to easily move all the
tables/sequences/etc. from the public schema in a database to a different
schema in a different database, but came up blank. If anyone has a
suggestion it would be appreciated.
Thanks,
Peter Darley
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 22 '05 #1
3 1954
Try this:
(tested for PostgreSQL 7.4)
CREATE OR REPLACE FUNCTION move_relation(VARCHAR, VARCHAR, VARCHAR)
RETURNS BOOL
AS '
-- $1 is the table name
-- $2 is the source schema
-- $3 is the destination schema
--
UPDATE pg_catalog.pg_class
SET relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
WHERE nspname = $3)
WHERE relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
WHERE nspname = $2)
AND relname = $1;

UPDATE pg_catalog.pg_type
SET typnamespace = (SELECT oid FROM pg_catalog.pg_namespace
WHERE nspname = $3)
WHERE typnamespace = (SELECT oid FROM pg_catalog.pg_namespace
WHERE nspname = $2)
AND typname = $1;

SELECT TRUE;
' LANGUAGE SQL;
----- Original Message -----
From: "Peter Darley" <pd*****@kinesis-cem.com>
To: "Pgsql-General" <pg***********@postgresql.org>
Sent: Tuesday, February 03, 2004 2:47 AM
Subject: [GENERAL] Transfer database tables to a schema

Folks,
I have a couple of databases that should really be schemas in the same
database. I tried to find suggestions on how to easily move all the
tables/sequences/etc. from the public schema in a database to a different
schema in a different database, but came up blank. If anyone has a
suggestion it would be appreciated.
Thanks,
Peter Darley
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 22 '05 #2
"Chris Travers" <ch***@travelamericas.com> writes:
Try this:


Er ... what about the indexes belonging to the relation?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 22 '05 #3
Ok, I see what you mean. I was looking at pg_index, when the indexes are
also listed in pg_class. I will have to add this and the pg_depend stuff.

Best Wishes,
Chris Travers

----- Original Message -----
From: "Tom Lane" <tg*@sss.pgh.pa.us>
To: "Chris Travers" <ch***@travelamericas.com>
Cc: "Peter Darley" <pd*****@kinesis-cem.com>; "Pgsql-General"
<pg***********@postgresql.org>
Sent: Wednesday, February 04, 2004 12:47 PM
Subject: Re: [GENERAL] Transfer database tables to a schema

"Chris Travers" <ch***@travelamericas.com> writes:
Try this:


Er ... what about the indexes belonging to the relation?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: midwesthills | last post by:
How can I transfer the schema of a database from one SQL Server app to another? I've used MySQL in the past and all I had to do is create a ..sql file with the DDL statements for the database,...
3
by: Robin Tucker | last post by:
Hi there, I have a database on my test machine that will need to be installed on users machines. I would like to create the database with the given schema on the users machine and also with...
0
by: Mike | last post by:
Hello, I'm trying to understand how to map hierarchical XML data to relational database tables, but I seem to be missing something. I'm not a database expert, but I know the basics. XML seems...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
7
by: mkarbarz | last post by:
Hello, I need to come up with a stored procedure that will allow me to read data from another database. The database I need to read the data from is a UniData residing on a Unix server. The...
8
by: situ | last post by:
Hello all, i have Database1 and database2, is it possible to make database connection to database2 by running stored procedure on database1. Thanks and Regards Situ
12
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a...
3
by: karanbikash | last post by:
Hi , I would like to know : 1.how to find all the schema in my DB2 database on Main frame machine . 2. How to see all the tables for a given schema . 3. What are the default schema in Db2 on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.