bit_and()

A function which returns the bitwise AND of all bits in the provided parameter

bit_and() is a system function which returns the bitwise AND of all bits in the provided parameter.

bit_and() was added in PostgreSQL 8.0.

Usage

bit_and ( smallint ) → smallint

bit_and ( integer ) → integer

bit_and ( bigint ) → bigint

bit_and ( bit ) → bit

Change history

Examples

Basic example for bit_and():

postgres=# CREATE TABLE foo (x INT);
CREATE TABLE

postgres=# INSERT INTO foo VALUES(100),(110),(111);
INSERT 0 3

postgres=# SELECT bit_and(x), bit_or(x), bit_xor(x) FROM foo;
 bit_and | bit_or | bit_xor 
---------+--------+---------
     100 |    111 |     101

Categories

System function

See also

bit_or(), bit_xor()