Casting integer to boolean

From: Bhuvan A <bhuvansql(at)linuxfreemail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Casting integer to boolean
Date: 2002-08-16 07:37:31
Message-ID: Pine.LNX.4.44.0208161249130.2342-100000@Bhuvan.bksys.co.in
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs 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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tod McQuillin 2002-08-16 07:48:49 Re: Casting integer to boolean
Previous Message Bruce Momjian 2002-08-16 04:53:59 Re: mistakes in postgresql-snapshots (7.3)

Browse pgsql-sql by date

  From Date Subject
Next Message Tod McQuillin 2002-08-16 07:48:49 Re: Casting integer to boolean
Previous Message Richard Huxton 2002-08-15 08:43:53 Re: Explicite typecasting of functions