Re: Casting integer to boolean - Mailing list pgsql-novice

From Mark S
Subject Re: Casting integer to boolean
Date
Msg-id 47B226A1.9080409@gravitycollege.com
Whole thread Raw
In response to (no subject)  (Mark S <mark@gravitycollege.com>)
List pgsql-novice
Scratch that... I have been at this too long and am
entirely confused about what server I'm working on (and consequently
what version).

Mark S wrote:
<font
 face="Tahoma">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 by date:

Previous
From: Mark S
Date:
Subject: (no subject)
Next
From: "Greg Cocks"
Date:
Subject: Seeking advice on how to build a pseudo-FK (?) relationship