Re: casting from integer to boolean

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: Seb <spluque(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: casting from integer to boolean
Date: 2008-03-26 22:46:08
Message-ID: 20080326224608.GR6870@frubble.xen.chris-lamb.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Mar 26, 2008 at 05:28:18PM -0500, Seb wrote:
> On Wed, 26 Mar 2008 15:11:47 -0700,
> "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com> wrote:
>
> [...]
>
> > INSERT INTO my_table (var_bool) VALUES ( CAST( 0 AS BOOLEAN )); or
> > INSERT INTO my_table (var_bool) VALUES (0::BOOLEAN);
>
>
> Thanks Richard. Is there a way to do it without changing the INSERT
> command? As I mentioned, there are many more columns of different
> types, so finding and replacing the VALUES would be very difficult.

You could turn the problem around and make the bool columns into ints
(which should be a simple search-and-replace, I hope) and then write
something (again hopefully simple) to turn them all back into bools.
I.e. lots of:

ALTER TABLE my_table ALTER var_bool TYPE bool USING var_bool::bool;

Either that or modify mdbtools. I've just had a look at its source and
gave up trying to understand it rather quickly.

Sam

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma 2008-03-26 22:46:47 Re: casting from integer to boolean
Previous Message Adam Rich 2008-03-26 22:34:59 Re: casting from integer to boolean