Re: CAST from VARCHAR to INT

Поиск
Список
Период
Сортировка
От Bhuvan A
Тема Re: CAST from VARCHAR to INT
Дата
Msg-id Pine.LNX.4.44.0301241126510.2081-100000@Bhuvan.bksys.co.in
обсуждение исходный текст
Ответ на CAST from VARCHAR to INT  ("Luke Pascoe" <luke.p@kmg.co.nz>)
Список pgsql-sql
> (Postgres 7.2.1)
> 
> I screwed up when I was designing a table a while back and made a column a
> VARCHAR that referenced (and should have been) an INT.
> 
> Now I'm trying to correct my mistake, I've created a new table and I'm
> trying to INSERT INTO...SELECT the data into it, but it's complaining that
> it can't stick a VARCHAR into an INT. All the values in the column are valid
> integers (the foreign key sees to that) but even a CAST won't do it.
> 
> How can I force it to copy/change the values?
> 

varchar cannot be casted to integer directly. Rather we can do it this 
way:

=> select your_varchar_field::text::int from your_table;

regards,
bhuvaneswaran




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

Предыдущее
От: Roberto Mello
Дата:
Сообщение: Re: Scheduling Events?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: CAST from VARCHAR to INT