Re: casting from integer to boolean

From: "Richard Broersma" <richard(dot)broersma(at)gmail(dot)com>
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:11:47
Message-ID: 396486430803261511y385f7eb6j7f378ac2e6ea3495@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Mar 26, 2008 at 2:58 PM, Seb <spluque(at)gmail(dot)com> wrote:
> INSERT INTO my_table (var_bool) VALUES (0);
> INSERT INTO my_table (var_bool) VALUES (1);
>
> So this results in an error. Unfortunately, there are many more columns
> and it would be very difficult to write a regexp to replace the 0s and
> 1s with their quoted versions. Is there any way to make such INSERT
> commands be valid? I have no experience with CAST, so any pointers
> would be welcome. Thanks.

INSERT INTO my_table (var_bool) VALUES ( CAST( 0 AS BOOLEAN ));
or
INSERT INTO my_table (var_bool) VALUES (0::BOOLEAN);

--
Regards,
Richard Broersma Jr.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Seb 2008-03-26 22:28:18 Re: casting from integer to boolean
Previous Message Seb 2008-03-26 21:58:27 casting from integer to boolean