Das geht ja auch anders, alter table … alter column … type …
danach kam der Fehler Error Code : 1025
Error on rename of etc…
ps: bei nicht primärschlüssel funktionierts !!!
DANKE IM VORAUS
Das geht auch bei PKs, man muß halt nur bedenken, das diese neben der Schönheit auch noch eine Aufgabe haben, die sie nicht erfüllen können, wenn der Typ sich ändert. Also, um den Typ zu ändern, sollte man sie erst einmal von ihrer Aufgabe entbinden:
test=# create table master (id char primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "master_pkey" for table "master"
CREATE TABLE
test=*# create table slave (id int primary key, fk_id char references master);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "slave_pkey" for table "slave"
CREATE TABLE
test=*# alter table slave drop constraint slave_fk_id_fkey;
ALTER TABLE
test=*# alter table slave alter column fk_id type int using fk_id::int;
ALTER TABLE
test=*# alter table master alter column id type int using id::int;
ALTER TABLE
test=*# alter table slave add constraint slave_fk_id_fkey FOREIGN KEY (fk_id) REFERENCES master(id);
ALTER TABLE
test=*# \d slave
Table "public.slave"
Column | Type | Modifiers
--------+---------+-----------
id | integer | not null
fk_id | integer |
Indexes:
"slave_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"slave_fk_id_fkey" FOREIGN KEY (fk_id) REFERENCES master(id)
Danke für den Hinweis. Ich hab nun mal geschaut, der Fragesteller schlug ja schon mehrfach mit MySQL-Fragen hier auf. Offensichtlich also lernresistent, daß er hier falsch ist.