Thread: boolean as 0 and 1

boolean as 0 and 1

From
"A B"
Date:
Hi,
Is there a way to make postgresql to automatically convert integer
values to boolean?

Consider

create table x (a boolean);
insert into x (a) values (1);

the inser fails :-(
Is there a way to make it work without altering the insert command?

Re: boolean as 0 and 1

From
"Shoaib Mir"
Date:


On Tue, Apr 8, 2008 at 7:54 PM, A B <gentosaker@gmail.com> wrote:
Hi,
Is there a way to make postgresql to automatically convert integer
values to boolean?

Consider

create table x (a boolean);
insert into x (a) values (1);

the inser fails :-(
Is there a way to make it work without altering the insert command?

 
 
Creating a custom cast might help you there....
 
--
Shoaib Mir
Fujitsu Australia Software Technology
shoaibm@fast.fujitsu.com.au

Re: boolean as 0 and 1

From
"Shoaib Mir"
Date:


On Tue, Apr 8, 2008 at 7:58 PM, Shoaib Mir <shoaibmir@gmail.com> wrote:
On Tue, Apr 8, 2008 at 7:54 PM, A B <gentosaker@gmail.com> wrote:
Hi,
Is there a way to make postgresql to automatically convert integer
values to boolean?

Consider

create table x (a boolean);
insert into x (a) values (1);

the inser fails :-(
Is there a way to make it work without altering the insert command?
 
 
 
Try using this:
 
create table x (a boolean);
insert into x (a) values (1::boolean);
 
It worked for me in 8.3
 
--
Shoaib Mir
Fujitsu Australia Software Technology

Re: boolean as 0 and 1

From
Aarni Ruuhimäki
Date:
On Tuesday 08 April 2008 12:54, A B wrote:
> Hi,
> Is there a way to make postgresql to automatically convert integer
> values to boolean?
>
> Consider
>
> create table x (a boolean);
> insert into x (a) values (1);
>
> the inser fails :-(
> Is there a way to make it work without altering the insert command?

Hi,

testing=# ALTER TABLE bar ADD a_boolean boolean;
ALTER TABLE
testing=# INSERT INTO bar (a_boolean) VALUES ('1');
INSERT 9459039 1


--
Aarni Ruuhimäki
---
Burglars usually come in through your windows.
---