(no subject)

Поиск
Список
Период
Сортировка
От Mark S
Тема (no subject)
Дата
Msg-id 47B21DA1.5030208@gravitycollege.com
обсуждение исходный текст
Ответы Re: Casting integer to boolean  (Mark S <mark@gravitycollege.com>)
Список pgsql-novice
Hello all,

I am new to PostgreSQL, coming from MySQL.  I have a question that
strikes me as simple but Google has failed to turn up any simple
answers.  I utilize bit masking in my code.  In MySQL I used this:

    SELECT * WHERE col & 3;

When I ported my code I was using an 8.1 PostgreSQL staging server, and
this worked:

    SELECT * WHERE (col & 3)::bool;

Now that I'm testing it in the 8.2 production server, it's telling me I
can't cast integer to bool.  I know I can just use (col & 3)
<> 0, and it's what I'm doing, but I feel like I'm missing
something that you can't convert an integer to a boolean.  What
surprised me even more was:

    SELECT 1::bit::bool;   -- ERROR:  cannot cast type bit to boolean

It also seems strange that you can't cast a bit to boolean.  So I guess
my question is one of curiosity, since I have a perfectly workable
solution (comparing against 0), but am I missing something here? I know
I can create my own casts but I feel like altering casting rules for
such a low-level type as integer and bool would be a bad idea.

Thanks,


Mark

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Obe, Regina"
Дата:
Сообщение: Re: Question regarding GROUP BY
Следующее
От: Mark S
Дата:
Сообщение: Re: Casting integer to boolean