Re: How to convert integer to boolean in insert - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: How to convert integer to boolean in insert
Date
Msg-id 20090405123612.GA5067@svana.org
Whole thread Raw
In response to How to convert integer to boolean in insert  (JiangMiao <jiangfriend@gmail.com>)
Responses Re: How to convert integer to boolean in insert
List 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.

Attachment

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: How to convert integer to boolean in insert
Next
From: Tom Lane
Date:
Subject: Re: How to convert integer to boolean in insert