Move a table to another schema

From: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Cc: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
Subject: Move a table to another schema
Date: 2003-11-17 16:05:04
Message-ID: 16312.61872.303145.799444@kelvin.csl.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have many tables created in the "public" schema and I would like to
migrate these into an "x001" schema. Unfortunately there is no ALTER
TABLE construct for this... The following SQL would seem to move the
"zxc" table from "public.zxc" to "x001.zxc":

UPDATE pg_class
SET relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'x001')
FROM pg_namespace
WHERE pg_class.relname = 'zxc' AND
pg_namespace.nspname = 'public' AND
pg_class.relnamespace = pg_namespace.oid

Has anyone else addressed this before? Recommendations?

Thanks, L.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2003-11-17 16:07:47 Re: Alternative cluster location
Previous Message btober 2003-11-17 16:03:18 Re: Alternative cluster location