From: | "Chris Travers" <chris(at)travelamericas(dot)com> |
---|---|
To: | "Peter Darley" <pdarley(at)kinesis-cem(dot)com>, "Pgsql-General" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Transfer database tables to a schema |
Date: | 2004-02-04 04:40:46 |
Message-ID: | 032a01c3eada$d61e83c0$aa44053d@winxp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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(at)kinesis-cem(dot)com>
To: "Pgsql-General" <pgsql-general(at)postgresql(dot)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 majordomo(at)postgresql(dot)org)
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | David Garamond | 2004-02-04 04:41:03 | Re: large crontab database design |
Previous Message | Cornelia Boenigk | 2004-02-04 02:31:48 | Re: BLOB problem |