(no subject)

From: Mark S <mark(at)gravitycollege(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: (no subject)
Date: 2008-02-12 22:28:49
Message-ID: 47B21DA1.5030208@gravitycollege.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#333333">
<font face="Tahoma">Hello all,<br>
<br>
I am new to PostgreSQL, coming from MySQL.&nbsp; I have a question that
strikes me as simple but Google has failed to turn up any simple
answers.&nbsp; I utilize bit masking in my code.&nbsp; In MySQL I used this:<br>
<br>
&nbsp;&nbsp;&nbsp; SELECT * WHERE col &amp; 3;<br>
<br>
When I ported my code I was using an 8.1 PostgreSQL staging server, and
this worked:<br>
<br>
&nbsp;&nbsp;&nbsp; SELECT * WHERE (col &amp; 3)::bool;<br>
<br>
Now that I'm testing it in the 8.2 production server, it's telling me I
can't cast integer to bool.&nbsp; I know I can just use (col &amp; 3)
&lt;&gt; 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.&nbsp; What
surprised me even more was:<br>
<br>
&nbsp;&nbsp;&nbsp; SELECT 1::bit::bool;&nbsp;&nbsp; -- ERROR:&nbsp; cannot cast type bit to boolean<br>
<br>
It also seems strange that you can't cast a bit to boolean.&nbsp; 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.<br>
<br>
Thanks,</font><br>
<div class="moz-signature">
<title></title>
<small><font face="Verdana"><b>Mark</b></font><br>
</small>
</div>
</body>
</html>

Attachment Content-Type Size
unknown_filename text/html 1.5 KB

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Mark S 2008-02-12 23:07:13 Re: Casting integer to boolean
Previous Message Obe, Regina 2008-02-12 14:51:37 Re: Question regarding GROUP BY