Thread: Re: How to increase Column width of table

Re: How to increase Column width of table

From
Christoph Haller
Date:
>
>  Atul here, i have one table and i would like to increase the length
of
>  existing column and the sql statement is
>
>        Exisiting Column  is "vehicle_make"  varchar(30)
>
>        SQL: alter table commute_profile alter column "vehicle_make"
> varchar(100)
>
>        But this gives error.
>
>        ERROR:  parser: parse error at or near "varchar"
>
I'm afraid there is no one-step-solution to this.
You'll have to go the hard way as

CREATE new_table (
...
... varchar(100),
...
);
INSERT INTO new_table as SELECT * FROM old_table;
DROP old_table;
ALTER TABLE new_table RENAME TO old_table;
And don't forget about re-creating related indexes etc.

Regards, Christoph



Re: How to increase Column width of table

From
Robert Treat
Date:
http://fts.postgresql.org/db/mw/msg.html?mid=1071582

On Tue, 2003-03-25 at 10:18, Christoph Haller wrote:
> >
> >  Atul here, i have one table and i would like to increase the length
> of
> >  existing column and the sql statement is
> >
> >        Exisiting Column  is "vehicle_make"  varchar(30)
> >
> >        SQL: alter table commute_profile alter column "vehicle_make"
> > varchar(100)
> >
> >        But this gives error.
> >
> >        ERROR:  parser: parse error at or near "varchar"
> >
> I'm afraid there is no one-step-solution to this.
> You'll have to go the hard way as
> 
> CREATE new_table (
> ...
> ... varchar(100),
> ...
> );
> INSERT INTO new_table as SELECT * FROM old_table;
> DROP old_table;
> ALTER TABLE new_table RENAME TO old_table;
> And don't forget about re-creating related indexes etc.
> 
> Regards, Christoph



Re: How to increase Column width of table

From
Andreas Pflug
Date:
Christoph Haller wrote:

>I'm afraid there is no one-step-solution to this.
>You'll have to go the hard way as
>
>CREATE new_table (
>...
>... varchar(100),
>...
>);
>INSERT INTO new_table as SELECT * FROM old_table;
>DROP old_table;
>ALTER TABLE new_table RENAME TO old_table;
>And don't forget about re-creating related indexes etc.
>
>Regards, Christoph
>  
>
This has many side effects, like dropped indices that have to be 
recreated etc.
You can rename your old column, create a new column varchar(100), update 
... set newCol=oldCol, drop oldCol and rename newCol to oldCol
See ALTER TABLE doc for this.

>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>  
>