changeing type of column

Started by Yuri A. Kabaenkovabout 24 years ago3 messagesgeneral
Jump to latest
#1Yuri A. Kabaenkov
sec@artofit.com

I've know that there is no function to change type of column in postgresql table.
But i have a table with serial field (sequence) and many other field.
And i need to change one field from int4 to varchar.

What is the best way to do it ?

--
Best regards,
Yuri mailto:sec@artofit.com

#2Devrim GUNDUZ
devrim@oper.metu.edu.tr
In reply to: Yuri A. Kabaenkov (#1)
Re: changeing type of column

Hi Yuri,

On Tue, 2 Apr 2002, Yuri A. Kabaenkov wrote:

I've know that there is no function to change type of column in postgresql table.
But i have a table with serial field (sequence) and many other field.
And i need to change one field from int4 to varchar.

What is the best way to do it ?

Just dump the database, edit the dump file, change the table definitions
in the dump file and reload the database...

Best regards,

--

Devrim GUNDUZ

devrim@oper.metu.edu.tr
devrim.gunduz@linux.org.tr
devrimg@tr.net

Web : http://devrim.oper.metu.edu.tr
------------------------------------------------------------------

#3Noname
wsheldah@lexmark.com
In reply to: Devrim GUNDUZ (#2)
Re: changeing type of column

Use the pg_dump command to dump both the schema and data to an ascii file. Make
a backup of that file, then edit it and change the column definition to varchar
(any reason not to use text instead?).

Then you'll want to write a short script to put single quotes around every
integer value of that column; I would probably use perl, but there are lots of
ways to do this.

Then just run pg_restore and you should be set. Hope this helps,

Wes

"Yuri A. Kabaenkov" <sec%artofit.com@interlock.lexmark.com> on 04/02/2002
01:18:48 PM

Please respond to "Yuri A. Kabaenkov" <sec%artofit.com@interlock.lexmark.com>

To: pgsql-general%postgresql.org@interlock.lexmark.com
cc: (bcc: Wesley Sheldahl/Lex/Lexmark)
Subject: [GENERAL] changeing type of column

I've know that there is no function to change type of column in postgresql
table.
But i have a table with serial field (sequence) and many other field.
And i need to change one field from int4 to varchar.

What is the best way to do it ?

--
Best regards,
Yuri mailto:sec@artofit.com

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