From: "Mark Seftel" <mark@trustemail.com>
To: <pgsql-novice@postgresql.org>
Subject: [NOVICE] changing the size of a column without losing data
Date sent: Thu, 22 Aug 2002 19:43:57 +0200
Like I said I make a lot of typo's
What I meant to write was:
begin;
ALTER table table0 RENAME TO table1;
DROP INDEX table0_pkey;
CREATE TEMPORARY table table1temp() INHERITS (table1);
INSERT INTO table1temp SELECT * FROM table1;
CREATE table table0(
field varchar(50) PRIMARY KEY);
INSERT INTO table0 SELECT * FROM table1temp;
DROP table table1temp;
DROP table table1;
end;
Though looking at it again I'm not sure why I used the temporary
table, this seems to work as well:
begin;
ALTER table table0 RENAME TO table1;
DROP INDEX table0_pkey;
CREATE table table0(
field varchar(50) PRIMARY KEY);
INSERT INTO table0 SELECT * FROM table1;
DROP table table1;
end;
Watch out for the data in the old column(100) being too big for the
new one (50),
Hope this actually helps
Paul Butler
> hi,
>
> How would i change a field which is currently char100 to char50?
>
> have tried:
> ALTER TABLE outlets MODIFY description varchar(50);
>
> but get error:
> parser: parse error at or near "modify"
>
> what is the correct command.
>
> Thx
>
> Mark
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)