How to completely move a table to another schema? - Mailing list pgsql-sql

From Chris Travers
Subject How to completely move a table to another schema?
Date
Msg-id 1071041216.2212.73.camel@localhost.localdomain
Whole thread Raw
Responses Re: How to completely move a table to another schema?
List pgsql-sql
Hi all;

I have a function which moves a table from one schema to another by
updating the relnamespace field of pg_class:

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)
WHEREtypnamespace = (SELECT oid FROM pg_catalog.pg_namespace                               WHERE nspname = $2)
    AND typname = $1;                                                                                      SELECT
TRUE;
' LANGUAGE SQL;                                                    
Am I missing anything?  I have already had a few problems that led me to discover 
that I needed to put in the second update query.  Just figured I would check.

Best Wishes,
Chris Travers



pgsql-sql by date:

Previous
From: Olivier Hubaut
Date:
Subject: Re: Bug in JDBC CREATE FUNCTION syntax?
Next
From: DHS Webmaster
Date:
Subject: first of month