Re: bitwise again

Lists: pgsql-general
From: Alexander Lohse <al(at)humantouch(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: bitwise again
Date: 2001-04-02 14:46:06
Message-ID: p05010400b6ee3e19eba1@[192.168.0.144]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi,

I am having serious troubles to move my DBs from MySQL to Postgres.

In MySQL I use following bitwise operation on an INT field:

$q = "select id from my_tbl where aid & 2";

In Postgres I tried the same, but I found no working solution.

My basic questions:

Is it better(or even possible) to use bitwise operator on an int4
field or shall I prefer the varbit?
(In my logic I would prefer int4!)

Using the above as in MySQL, I get an ERROR:
WHERE clause must return type bool, not type int4

Can anyone point me to a right doc or kickstart myself?

Thanx,

Alex

--
___________________________
Alexander Lohse
Human Touch Medienproduktion GmbH
Am See 1
17440 Klein Jasedow

Tel: (038374) 75211
Fax: (038374) 75223
eMail: al(at)humantouch(dot)de
http://www.humantouch.de


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Alexander Lohse <al(at)humantouch(dot)de>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: bitwise again
Date: 2001-04-02 16:43:49
Message-ID: Pine.LNX.4.30.0104021839400.1287-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Alexander Lohse writes:

> In MySQL I use following bitwise operation on an INT field:
>
> $q = "select id from my_tbl where aid & 2";
>
> In Postgres I tried the same, but I found no working solution.

Upgrade to 7.1.

> Is it better(or even possible) to use bitwise operator on an int4
> field or shall I prefer the varbit?

If you plan on bit fields larger than 32 bits and/or you need string-like
functions (substring, position), then BIT or BIT VARYING are for you. If
you plan to use numeric operators (+, sqrt), then use an integer type.

> Using the above as in MySQL, I get an ERROR:
> WHERE clause must return type bool, not type int4

Indeed. Maybe you meant something like (aid & 2) <> 0.

--
Peter Eisentraut peter_e(at)gmx(dot)net http://yi.org/peter-e/


From: Philip Hallstrom <philip(at)adhesivemedia(dot)com>
To: Alexander Lohse <al(at)humantouch(dot)de>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: bitwise again
Date: 2001-04-02 19:11:48
Message-ID: Pine.BSF.4.31.0104021208290.27324-300000@oddjob.adhesivemedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

As someone else pointed out you can upgrade to 7.1. Or you can add your
own operators/functions.

I've included the C source and SQL create script. You'll need to do this
as the postgres superuser. And you'll probably need to edit the SQL
script and adjust the path of the .so file. The .c file has what I use
for compilation (you'll need to tweak that as well).

The only gotcha is that you can't remove the NOT operator (it's a bug in
7.0.3) using the DROP OPERATOR statement.

-philip

On Mon, 2 Apr 2001, Alexander Lohse wrote:

> Hi,
>
> I am having serious troubles to move my DBs from MySQL to Postgres.
>
> In MySQL I use following bitwise operation on an INT field:
>
> $q = "select id from my_tbl where aid & 2";
>
> In Postgres I tried the same, but I found no working solution.
>
> My basic questions:
>
> Is it better(or even possible) to use bitwise operator on an int4
> field or shall I prefer the varbit?
> (In my logic I would prefer int4!)
>
> Using the above as in MySQL, I get an ERROR:
> WHERE clause must return type bool, not type int4
>
> Can anyone point me to a right doc or kickstart myself?
>
> Thanx,
>
> Alex
>
>
>
> --
> ___________________________
> Alexander Lohse
> Human Touch Medienproduktion GmbH
> Am See 1
> 17440 Klein Jasedow
>
> Tel: (038374) 75211
> Fax: (038374) 75223
> eMail: al(at)humantouch(dot)de
> http://www.humantouch.de
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>

Attachment Content-Type Size
am_int_bit_operators.c text/plain 1.1 KB
create.sql text/plain 3.6 KB