Re: changing field length

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Jodi Kanter <jkanter(at)virginia(dot)edu>
Cc: Bruno Wolff III <bruno(at)wolff(dot)to>, Gaetano Mendola <mendola(at)bigfoot(dot)com>, <pgsql-admin(at)postgresql(dot)org>
Subject: Re: changing field length
Date: 2003-08-20 15:48:39
Message-ID: Pine.LNX.4.33.0308200929520.12206-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

As always, there's more than one way to skin a cat...

Create a new table and insert into it:

create newtable (field newdef, field2 newdef);
insert into
newtable (
select oldfield,
oldfield2 from oldtable
);

Create it on the fly with Postgresql casting shortcuts:
select
field1::newtype,
field2::newtype,
field3,
field4
into
newtable
from
oldtable;

Create it on the fly with ANSI style casting:
select
cast(field1 as newtype),
cast(field2 as newtype),
field3,
field4
into
newtable
from
oldtable;

On Wed, 20 Aug 2003, Jodi Kanter wrote:

> Ok. so for now I want to return to where I started. so I renamed the
> table and regenerated my original table with the fields in the order
> that I like. I cannot just do a
> insert into table select * from other_table;
> because the fields are in a different order.
> Can I do this by listing the fields in my insert in the order in which I
> want them placed?
> Thanks
> Jodi
>
> Bruno Wolff III wrote:
>
> >On Wed, Aug 20, 2003 at 10:49:08 -0400,
> > Jodi Kanter <jkanter(at)virginia(dot)edu> wrote:
> >
> >>can I now make this field not null?
> >>
> >>is it possible to move a field up in a table? now that I have done this
> >>
> >
> >Currently, not without recreating the table. There was some discussion
> >about that a few months ago, but nothing is happening in 7.4 on that
> >front. Maybe in 7.5 there will be a way to change the column order,
> >but don't count on it.
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
> >
>
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Brian McCane 2003-08-20 16:00:48 Compression of text fields
Previous Message Stephan Szabo 2003-08-20 15:45:46 Re: Explicit Cast