Re: Transfer database tables to a schema - Mailing list pgsql-general

From Chris Travers
Subject Re: Transfer database tables to a schema
Date
Msg-id 032a01c3eada$d61e83c0$aa44053d@winxp
Whole thread Raw
In response to Transfer database tables to a schema  ("Peter Darley" <pdarley@kinesis-cem.com>)
Responses Re: Transfer database tables to a schema
List 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@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


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


pgsql-general by date:

Previous
From: Steve Atkins
Date:
Subject: Re: application developers list?? or report engine using postgres?
Next
From: Tom Lane
Date:
Subject: Re: Transfer database tables to a schema