create new field

Поиск
Список
Период
Сортировка
От Chris Faulkner
Тема create new field
Дата
Msg-id DGENKIKMJILAAKJGFHKFAEHPCIAA.chrisf@oramap.com
обсуждение исходный текст
Ответы Re: create new field  (Josh Berkus <josh@agliodbs.com>)
Re: create new field  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-sql
Hello

I would like to change the type of a column. At the moment, it is varchar(4)
but I would like it to be int. All values in the field at the moment are
actually integer.

I tried a way I had seen in the archives - it foes along the lines of adding
a column, using update, drop the old column and rename the new one.

alter table tab add column new_col int4;
update tab set new_col = "OLD_COL";
ERROR:  column "new_col" is of type integer but expression is of type
characte
r       You will need to rewrite or cast the expression

OK - so I tried casting.

template1=# update tab set new_col = "OLD_COL"::int4;
ERROR:  Cannot cast type character to integer

I understand this - some tables might have characters in the varchar but how
to get around it in my case ? I know that my character field has only
integers in it ?

Thanks

Chris




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

Предыдущее
От: Wei Weng
Дата:
Сообщение: suggestion needed for implementation
Следующее
От: "Louise Cofield"
Дата:
Сообщение: Re: Multiple table join