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

田中謙介 kentana7245 @ gmail.com
2013年 4月 25日 (木) 19:21:51 JST


ご教授いただき、ありがとうございます。
助かります!
早速、試させていただきます。
本当にありがとうございます!

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 メーリングリストの案内