From: Tim DeMarco <Tim.DeMarco@myrio.com>
To: pgsql-admin@postgresql.org
Subject: Renaming tables
Date: Mon, 11 Mar 2002 16:06:28 -0800
Message-ID: <A015F722AB845E4B8458CBABDFFE634203D29C@mail0.myrio.com> (raw)
Hi,
I'm running postgres 7.0.3 on Sun 220R (1Gig Ram) with Solaris2.8 (upgrading to 7.1.3 or 7.2 very soon)
I have several tables I am planning on renaming and ran into a little trouble. I know I can fix the problem, but I'm hoping there is an easier solution. Here is an example: I rename usergroupstatus to usergroupstatusvalues. I did a dump of the this table as well as a table that has a Fkey to this table:
CREATE TABLE "usergroupstatusvalues" (
"status" character varying(25) NOT NULL,
PRIMARY KEY ("status")
);
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER DELETE ON "usergroupstatusvalues" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_del" ('<unnamed>', 'usergroup', 'usergroupstatus', 'UNSPECIFIED', 'status', 'status');
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER UPDATE ON "usergroupstatusvalues" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_upd" ('<unnamed>', 'usergroup', 'usergroupstatus', 'UNSPECIFIED', 'status', 'status');
CREATE TABLE "usergroup" (
"id" numeric(11,0),
"name" character varying(50) NOT NULL,
"groupid" character varying(2) NOT NULL,
"issystemadmin" numeric(1,0),
"lastupdatedatetime" character varying(50),
"lastupdateuserid" character varying(30),
"recordstatuscode" character varying(2) NOT NULL,
"location" character varying(5) NOT NULL,
"status" character varying(25) NOT NULL,
"timestamp" character varying(30),
PRIMARY KEY ("groupid")
);
CREATE UNIQUE INDEX "usergroup_id_unique" on "usergroup" using btree ( "id" "numeric_ops" );
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "usergroup" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_check_ins" ('<unnamed>', 'usergroup', 'recordstatuscodes', 'UNSPECIFIED', 'recordstatuscode', 'code');
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER INSERT OR UPDATE ON "usergroup" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_check_ins" ('<unnamed>', 'usergroup', 'usergroupstatus', 'UNSPECIFIED', 'status', 'status');
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER DELETE ON "usergroup" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_del" ('<unnamed>', 'usergroupsignals', 'usergroup', 'UNSPECIFIED', 'id', 'id');
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER UPDATE ON "usergroup" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_upd" ('<unnamed>', 'usergroupsignals', 'usergroup', 'UNSPECIFIED', 'id', 'id');
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER DELETE ON "usergroup" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_del" ('<unnamed>', 'usertable', 'usergroup', 'UNSPECIFIED', 'groupid', 'groupid');
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER UPDATE ON "usergroup" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_upd" ('<unnamed>', 'usertable', 'usergroup', 'UNSPECIFIED', 'groupid', 'groupid');
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER DELETE ON "usergroup" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_del" ('<unnamed>', 'securityaccessprofile', 'usergroup', 'UNSPECIFIED', 'groupid', 'groupid');
CREATE CONSTRAINT TRIGGER "<unnamed>" AFTER UPDATE ON "usergroup" NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE PROCEDURE "RI_FKey_noaction_upd" ('<unnamed>', 'securityaccessprofile', 'usergroup', 'UNSPECIFIED', 'groupid', 'groupid');
The constraints still refer to the original table name (usergroupstatus). I know that I can drop and re-create the tables and have them refer to the new table, but I'm hoping there is a better way. Also, if I need to recreate the tables should I use the statements above (generated by pg_dump) and manually modify the constraints?
Thanks in advance!
Tim DeMarco
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: Tim.DeMarco@myrio.com
Subject: Re: Renaming tables
In-Reply-To: <A015F722AB845E4B8458CBABDFFE634203D29C@mail0.myrio.com>
References: <A015F722AB845E4B8458CBABDFFE634203D29C@mail0.myrio.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox