Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I modify a datatype in 7.2.15

Status
Not open for further replies.

newbiepg

Programmer
Nov 6, 2002
181
IN
I have a column which is registered as integer I would like to change it to varchar
Is this possible through sql?
 

i don think so. coz i've tried it before. i read a forum saying that it cant be change. don know whether true or not. maybe u can copy out ur data to a file and re-create the table. after re-creating the table, copy back the data from the file into ur new table. it works for me. hope to hear some other suggestions. cheerss...
 
Using PostgreSQL 7.3.1 you could do something like:

[tt]ALTER TABLE <table> RENAME COLUMN <col> TO tempcol;
ALTER TABLE <table> ADD COLUMN <col> VARCHAR(32);
UPDATE <table> SET <col>=tempcol;
ALTER TABLE <table> DROP COLUMN tempcol;[/tt]
 
In 7.2, by the way, you could do everything up to the [tt]DROP COLUMN[/tt]. You would not be able to drop the renamed column from the database without creating a new table and copying the data from one to the other.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top