[pgsql-jp: 41389] Re: PostgreSQLでのKEY変更方法について

Suzuki Hironobu hironobu @ interdb.jp
2013年 4月 25日 (木) 19:31:32 JST


ミスがありました。
serial -> integerなので、ALTER TABLE ALTER TYPEは不要でした。
DROP SEQUENCE foo_col_seq CASCADEだけでOKです。

#笠原さんのALTER TABLE DROP DEFAULTか、どちらか好みのほうを使ってください。


On 2013年04月25日 19:21, 田中謙介 wrote:
> ご教授いただき、ありがとうございます。
> 助かります!
> 早速、試させていただきます。
> 本当にありがとうございます!
>
> 2013/04/25 Suzuki Hironobu <hironobu @ interdb.jp>:
>> On 2013年04月25日 17:59, 田中謙介 wrote:
>>> PostgreSQLで、SERIAL PRIMARY KEY を INTEGER PRIMARY KEY に変更する方法がわからず、困っています。
>>> どなたかご存知の方、宜しくお願いします。
>>>
>>
>> ALTER TABLE ALTER TYPEとDROP SEQUENCEで変更できます。
>> 適宜、テーブル名、カラム名、シーケンス名を読みかえてください。
>>
>>
>> ps=# CREATE TABLE foo (col serial primary key);
>> CREATE TABLE
>>
>> ps=# \d foo
>> Table "public.foo"
>> Column | Type | Modifiers
>> --------+---------+---------------------------------------------------
>> col | integer | not null default nextval('foo_col_seq'::regclass)
>> Indexes:
>> "foo_pkey" PRIMARY KEY, btree (col)
>>
>> ps=# ALTER TABLE foo ALTER col TYPE int;
>> ALTER TABLE
>> ps=# \d foo
>> Table "public.foo"
>> Column | Type | Modifiers
>> --------+---------+---------------------------------------------------
>> col | integer | not null default nextval('foo_col_seq'::regclass)
>> Indexes:
>> "foo_pkey" PRIMARY KEY, btree (col)
>>
>> ps=# DROP SEQUENCE foo_col_seq CASCADE;
>> DROP SEQUENCE
>>
>> ps=# \d foo
>> Table "public.foo"
>> Column | Type | Modifiers
>> --------+---------+-----------
>> col | integer | not null
>> Indexes:
>> "foo_pkey" PRIMARY KEY, btree (col)
>>
>>
>>
>



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