staltentyp ändern

Hallo,
ich habe in einer Anwendung (egroupware) die Datenbank von MySQL nach PostgreSQL 9.0 mit dem dazugehörigen Tool übernommen.
Bei einer Unter-Anwendung erhalte ich die Fehlermeldung, das der Spaltentyp in einer bestimmten Tabelle nicht stimmt.
MySQL hat die Spalten als “smalint” deklariert.
Die Anwendung erwartete jedoch “bool”
Smalint ist 2 Bit breit, ist real jedoch nur mit 0 und 1 gefüllt.
Wie kann ich den Typ der Spalte so umwandeln, das daraus “boolean” wird?
ALTER TABLE xxx ALTER COLUMN yyy TYPE boollean
bringt mit Syntax-Fehler wie:
ALTER TABLE egw_felamimail_accounts ALTER COLUMN fm_active TYPE boolean;
FEHLER: Spalte »fm_active« kann nicht in Typ boolean umgewandelt werden

Wie kann man das richtig machen?



test=# create table puba (i int);
CREATE TABLE
test=*# insert into puba values (0);
INSERT 0 1
test=*# insert into puba values (1);
INSERT 0 1
test=*# commit;
COMMIT
test=# alter table puba alter column i type bool using i::bool;
ALTER TABLE
test=*# \d puba
     Table "public.puba"
 Column |  Type   | Modifiers
--------+---------+-----------
 i      | boolean |

Andreas

Hallo Andreas,
danke für die schnelle Antwort,
Mit der Beispieltabelle unt i als Integer funktioniert das,
Mit der Spalte als “smallint” hat Postgres Probleme:


egroupware=# ALTER TABLE egw_felamimail_accounts ALTER COLUMN fm_active TYPE bool using fm_active::bool;
FEHLER: kann Typ smallint nicht in Typ boolean umwandeln
egroupware=#


Gruß
Armin

Okay:

test=# create table puba (i smallint);
CREATE TABLE
test=*# copy puba from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> 1
>> 2
>> \.
test=*# commit;
COMMIT
test=# alter table puba alter column i type bool using (case when i = 0 then false else true end);
ALTER TABLE
test=*# \d puba;
     Table "public.puba"
 Column |  Type   | Modifiers
--------+---------+-----------
 i      | boolean |

Andreas

Hallo Andreas,
damit klappts, danke.
Gruß
Armin