Casting integer to boolean

Поиск
Список
Период
Сортировка
От Bhuvan A
Тема Casting integer to boolean
Дата
Msg-id Pine.LNX.4.44.0208161249130.2342-100000@Bhuvan.bksys.co.in
обсуждение исходный текст
Ответы Re: Casting integer to boolean  (Tod McQuillin <devin@spamcop.net>)
Список 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 по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Explicite typecasting of functions
Следующее
От: Tod McQuillin
Дата:
Сообщение: Re: Casting integer to boolean