Re: bitwise AND?

Поиск
Список
Период
Сортировка
От Lamar Owen
Тема Re: bitwise AND?
Дата
Msg-id 39AEA856.F5716533@wgcr.org
обсуждение исходный текст
Ответ на bitwise AND?  (Vince Vielhaber <vev@michvhf.com>)
Список pgsql-hackers
Vince Vielhaber wrote:
> Do we have any kind of bitwise AND?

Non directly.
>    select foo from bar where (foo AND 2);

Ok, you _can_ do this; it's just a big pain to do so.

First, decompose any bitwise AND into TESTBIT and logical AND
operators.  TESTBIT is the same as AND, just having a single bit set.

In your example, AND 2 is already a single bit.  But, I'm going to
illustrate the general solution: suppose we have AND 7 -- decompose into
(foo TESTBIT 4) AND (foo TESTBIT 2) AND (foo TESTBIT 1).

Now, rewrite that to:
((foo % 8)/4)*((foo % 4)/2)*((foo % 2)/1) -- if the result is greater
than zero, the logical AND is true.

For bitwise OR, substitute integer + for integer * above.

For your case, write the query:

select foo from bar where ((foo % 4)/2)>0

AFAIK and have tested, that should work the way you think it should. (I
knew those exercise in Z80 machine language would come in handy! :-))
--
Lamar Owen
WGCR Internet Radio
1 Peter 4:11


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

Предыдущее
От: Mark Hollomon
Дата:
Сообщение: new relkind for view
Следующее
От: Rini Dutta
Дата:
Сообщение: optimal performance for inserts