Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 22nd, 2005, 08:50 AM
Peter Darley
Guest
 
Posts: n/a
Default 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 majordomo@postgresql.org)




  #2  
Old November 22nd, 2005, 08:50 AM
Chris Travers
Guest
 
Posts: n/a
Default Re: Transfer database tables to a schema

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" <pdarley@kinesis-cem.com>
To: "Pgsql-General" <pgsql-general@postgresql.org>
Sent: Tuesday, February 03, 2004 2:47 AM
Subject: [GENERAL] Transfer database tables to a schema

[color=blue]
> 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 majordomo@postgresql.org)
>
>[/color]


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

  #3  
Old November 22nd, 2005, 08:50 AM
Tom Lane
Guest
 
Posts: n/a
Default Re: Transfer database tables to a schema

"Chris Travers" <chris@travelamericas.com> writes:[color=blue]
> Try this:[/color]

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 majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

  #4  
Old November 22nd, 2005, 08:52 AM
Chris Travers
Guest
 
Posts: n/a
Default Re: Transfer database tables to a schema

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" <tgl@sss.pgh.pa.us>
To: "Chris Travers" <chris@travelamericas.com>
Cc: "Peter Darley" <pdarley@kinesis-cem.com>; "Pgsql-General"
<pgsql-general@postgresql.org>
Sent: Wednesday, February 04, 2004 12:47 PM
Subject: Re: [GENERAL] Transfer database tables to a schema

[color=blue]
> "Chris Travers" <chris@travelamericas.com> writes:[color=green]
> > Try this:[/color]
>
> Er ... what about the indexes belonging to the relation?
>
> regards, tom lane
>
>[/color]


---------------------------(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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.