Re: Changing column data type on an existing table

Поиск
Список
Период
Сортировка
От Brad Nicholson
Тема Re: Changing column data type on an existing table
Дата
Msg-id 4284EB51.6040001@ca.afilias.info
обсуждение исходный текст
Ответ на Changing column data type on an existing table  (Joe Audette <joe_audette@yahoo.com>)
Ответы Re: Changing column data type on an existing table  (Bricklen Anderson <BAnderson@PresiNET.com>)
Список pgsql-general
Something like

BEGIN;
LOCK table_name;
ALTER TABLE table_name RENAME col_a to col_a_old;
ALTER TABLE table_name ADD COLUMN col_a text;
UPDATE table_name SET col_a=col_a_old;
ALTER TABLE table_name DROP COLUMN col_a_old;
COMMIT;

If you have any referential integrity on the column, you'll have to mess
with that first.


Joe Audette wrote:

>Hi,
>
>I have an app that I released with a particular field
>as varchar 255.
>
>Can someone give me a script example I can use to make
>an upgrade script to change it to text or at least to
>larger varchar without losing existing data?
>
>I support 3 different dbs in my app, Postgre is the
>newest and least familiar to me but I am trying to
>learn.
>
>Any help much appreciated.
>
>Joe Audette
>
>joe_audette [at] yahoo dotcom
>http://www.joeaudette.com
>http://www.mojoportal.com
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>


--
Brad Nicholson  416-673-4106
Database Administrator, Afilias Canada Corp.


В списке pgsql-general по дате отправления:

Предыдущее
От: Joe Audette
Дата:
Сообщение: Changing column data type on an existing table
Следующее
От: Bricklen Anderson
Дата:
Сообщение: Re: Changing column data type on an existing table