[pgsql-jp: 39069] インデックス名を変更してもpg_constraintが更新されない

yoko00068 yoko00068 @ gmail.com
2008年 1月 25日 (金) 14:02:51 JST


こんにちは星野と申します

テーブルのバックアップ的なコピーを作ろうと
テーブル名(ALTER TABLE)、インデックス名(ALTER INDEX)を変更し
元々の名前で新しいテーブルを作成しました

そこまでは問題なかったのですが、pg_dumpのダンプデータから
リストアしたところ、重複エラーになってしまいました

>ERROR:  relation "hogehoge_pkey" already exists

どうやらALTER INDEX でリネームしても
pg_constraint カタログの名前が変わらないようです。

とりあえずはDROP INDEX したあとテーブル/インデックスを
作り直せば良いと思いますが、

ALTER INDEX hogehoge RENAME TO で変更されるべきものだと思います
(またはALTER TABLE ALTER CONSTRAINT RENAME TO ?)

なにか勘違いしているようでしたらご指摘いただきたく

少々長いですが、再現ログです
---
[postgres @ hoshino-centos ~]$ createdb test
[postgres @ hoshino-centos ~]$ psql -d test

test=# create table test (id int
test=# CREATE TABLE test (id int PRIMARY KEY) ;
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"test_pkey" for table "test"
CREATE TABLE

test=# ALTER TABLE test RENAME TO test_bak ;
ALTER TABLE
test=# ALTER INDEX test_pkey RENAME TO test_bak_pkey ;
ALTER INDEX

test=# \d test_bak
   Table "public.test_bak"
 Column |  Type   | Modifiers
--------+---------+-----------
 id     | integer | not null
Indexes:
    "test_bak_pkey" PRIMARY KEY, btree (id)

test=# \q
[postgres @ hoshino-centos ~]$ pg_dump -d test > test.sql
[postgres @ hoshino-centos ~]$ cat test.sql | grep test_pkey
-- Name: test_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
    ADD CONSTRAINT test_pkey PRIMARY KEY (id);

[postgres @ hoshino-centos ~]$ psql -d test

test=# \x
Expanded display is on.

test=# select * from pg_constraint where conname like 'test%' ;
-[ RECORD 1 ]-+----------
conname       | test_pkey
connamespace  | 2200
contype       | p
condeferrable | f
condeferred   | f
conrelid      | 11615789
contypid      | 0
confrelid     | 0
confupdtype   |
confdeltype   |
confmatchtype |
conkey        | {1}
confkey       |
conbin        |
consrc        |

test=#



pgsql-jp メーリングリストの案内