Casting integer to boolean - Mailing list pgsql-sql

From Bhuvan A
Subject Casting integer to boolean
Date
Msg-id Pine.LNX.4.44.0208161249130.2342-100000@Bhuvan.bksys.co.in
Whole thread Raw
Responses Re: Casting integer to boolean  (Tod McQuillin <devin@spamcop.net>)
List pgsql-sql
Hi,

I am using postgresql 7.2.1.

How do i cast an integer value to boolean? I did try the below sequence of
SQLs and was little bit confused, by the way it behaves. It casts the
integer value to boolean in one case but not ever again.

bhuvan=> SELECT count(*)::int::boolean from my_table;
ERROR:  Cannot cast type 'integer' to 'boolean'
bhuvan=> -- The SQL similar to the above SQL is my requirement
bhuvan=> SELECT true where (1);
ERROR:  WHERE clause must return type boolean, not type integer
bhuvan=> SELECT true where (1::boolean);bool
------t
(1 row)

bhuvan=> SELECT true where (1::int::boolean);
ERROR:  Cannot cast type 'integer' to 'boolean'
bhuvan=>

I donot know whether i am wrong or its a bug. I request someone to correct
me if i am wrong or please suggest me the right way to cast an integer to
boolean as, returning true for non-zero value, false otherwise.

regards, 
bhuvaneswaran




pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Explicite typecasting of functions
Next
From: Tod McQuillin
Date:
Subject: Re: Casting integer to boolean