Re: Changing colums type

From: "A(dot)Bhuvaneswaran" <bhuvansql(at)myrealbox(dot)com>
To: Andrei Verovski <andreil1(at)mail(dot)starlett(dot)lv>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Changing colums type
Date: 2003-05-02 09:36:51
Message-ID: Pine.LNX.4.44.0305021455370.3040-100000@Bhuvan.bksys.co.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message JEANARTHUR 2003-05-02 09:59:56 problem after an hd failure
Previous Message Andrei Verovski (aka MacGuru) 2003-05-02 08:51:25 Changing colums type