pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: A.Bhuvaneswaran <bhuvansql@myrealbox.com>
Cc: Andrei Verovski <andreil1@mail.starlett.lv>
Cc: pgsql-admin@postgresql.org
Subject: Re: Changing colums type
Date: Fri, 2 May 2003 09:18:30 -0700 (PDT)
Message-ID: <20030502091054.A65288-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0305021455370.3040-100000@Bhuvan.bksys.co.in>


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.




view thread (3+ messages)

Message-ID: <20030502091054.A65288-100000@megazone23.bigpanda.com>
Permalink:  ../20030502091054.A65288-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/20030502091054.A65288-100000@megazone23.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, bhuvansql@myrealbox.com, andreil1@mail.starlett.lv
  Subject: Re: Changing colums type
  In-Reply-To: <20030502091054.A65288-100000@megazone23.bigpanda.com>
  References: <Pine.LNX.4.44.0305021455370.3040-100000@Bhuvan.bksys.co.in> <20030502091054.A65288-100000@megazone23.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox