X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A62EE475F6A for ; Fri, 2 May 2003 12:18:30 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 09E6B475E9D for ; Fri, 2 May 2003 12:18:30 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 387E4D60D; Fri, 2 May 2003 09:18:30 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 2E2B95C0B; Fri, 2 May 2003 09:18:30 -0700 (PDT) Date: Fri, 2 May 2003 09:18:30 -0700 (PDT) From: Stephan Szabo To: "A.Bhuvaneswaran" Cc: Andrei Verovski , Subject: Re: Changing colums type In-Reply-To: Message-ID: <20030502091054.A65288-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Status: No, hits=-26.4 required=5.0 tests=BAYES_00,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, QUOTE_TWICE_1,REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/27 X-Sequence-Number: 8589 On Fri, 2 May 2003, A.Bhuvaneswaran wrote: > > 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; I think this second way is a bad idea if there's already data in the table since I don't think it'll preserve values properly and in simple tests has gotten me crashes depending on what follows it.