Re: Changing colums type - Mailing list pgsql-admin

From A.Bhuvaneswaran
Subject Re: Changing colums type
Date
Msg-id Pine.LNX.4.44.0305021455370.3040-100000@Bhuvan.bksys.co.in
Whole thread Raw
In response to Changing colums type  (Andrei Verovski (aka MacGuru) <andreil1@mail.starlett.lv>)
Responses Re: Changing colums type  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-admin
> Hi,
>
> I would like to change column type from int8 to int4 in psql command
> line utility. I am run command ALTER TABLE blah blah blah, but nothing
> happens. No error message and no change of column type. Anyone have a
> clue what is happening?

Way 1:

=> BEGIN;
=> ALTER TABLE my_table ADD COLUMN new_column int4;
=> UPDATE my_table SET new_column = old_column;
=> ALTER TABLE my_table DROP COLUMN old_column;
=> COMMIT;

Way 2:

=# BEGIN;
=# UPDATE pg_attribute SET atttypid = pg_type.oid WHERE attrelid =
pg_class.oid AND pg_class.relnamespace = pg_namespace.oid AND
pg_namespace.nspname = 'my_schema' AND pg_class.relname = 'my_table' AND
pg_attribute.attname = 'my_column' AND pg_type.typname = 'int4';
=# COMMIT;

Hope it helps.

regards,
bhuvaneswaran


pgsql-admin by date:

Previous
From: Andrei Verovski (aka MacGuru)
Date:
Subject: Changing colums type
Next
From: JEANARTHUR@EUROVOX.FR
Date:
Subject: problem after an hd failure