Re: How to convert integer to boolean in insert

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: How to convert integer to boolean in insert
Дата
Msg-id 20090405123612.GA5067@svana.org
обсуждение исходный текст
Ответ на How to convert integer to boolean in insert  (JiangMiao <jiangfriend@gmail.com>)
Ответы Re: How to convert integer to boolean in insert  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
On Sun, Apr 05, 2009 at 04:14:37AM -0700, JiangMiao wrote:
> and I found a way to add the cast
> insert into foo(banned) values(0::boolean)
> but I have a big table which dump from mysqldump and covert by
> mysql2pgsql. all of boolean relation values is 0 instead of '0' or
> FALSE.
>
> Is there any way to make pgsql implicit cast the integer to boolean?

You probably don't want implicit, since that will probably trip you up
somewhere else. You want an assignment cast. The fucntion you want
exists, called 'bool'.

# select castfunc::regproc from pg_cast where castsource = 'int4'::regtype and casttarget = 'boolean'::regtype;
 castfunc
----------
 bool
(1 row)

You might want to create the cast temporarily and after the import
remove it again.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

Вложения

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

Предыдущее
От: Thomas Kellerer
Дата:
Сообщение: Re: How to convert integer to boolean in insert
Следующее
От: Tom Lane
Дата:
Сообщение: Re: How to convert integer to boolean in insert