Re: bitwise again

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
Thread:
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/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-04-02 16:47:55 Re: Indexes vs indices
Previous Message Trond Eivind =?iso-8859-1?q?Glomsr=F8d?= 2001-04-02 16:35:57 Re: Need PostgreSQL startup scripts