Re: How to convert integer to boolean in insert

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: JiangMiao <jiangfriend(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to convert integer to boolean in insert
Date: 2009-04-05 12:36:12
Message-ID: 20090405123612.GA5067@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-04-05 16:00:47 Re: How to convert integer to boolean in insert
Previous Message Thomas Kellerer 2009-04-05 12:19:14 Re: How to convert integer to boolean in insert