Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitwise operators in Postgres

I have a problem with using Bitwise operators in Postgres I get the following error message

ERROR:  argument of WHERE must be type boolean, not type integer

My query looks as below

SELECT DISTINCT number,name,contact,special FROM clients WHERE special & 2048;

Any help will be appreciated

like image 472
Elitmiar Avatar asked Jul 30 '09 09:07

Elitmiar


People also ask

What is bit in PostgreSQL?

Bit strings are strings of 1's and 0's. They can be used to store or visualize bit masks. There are two SQL bit types: bit( n ) and bit varying( n ) , where n is a positive integer. bit type data must match the length n exactly; it is an error to attempt to store shorter or longer bit strings.

What is operator in PostgreSQL?

An operator is a reserved word or a character used primarily in a PostgreSQL statement's WHERE clause to perform operation(s), such as comparisons and arithmetic operations. Operators are used to specify conditions in a PostgreSQL statement and to serve as conjunctions for multiple conditions in a statement.

How do I add two numbers in PostgreSQL?

PostgreSQL INSERT Multiple Rows First, specify the name of the table that you want to insert data after the INSERT INTO keywords. Second, list the required columns or all columns of the table in parentheses that follow the table name. Third, supply a comma-separated list of rows after the VALUES keyword.


1 Answers

You'll need to do a comparison:

SELECT DISTINCT number, ..., special FROM clients WHERE special & 2048 = 2048;

or

SELECT DISTINCT number, ..., special FROM clients WHERE special & 2048 > 0;
like image 161
Tomalak Avatar answered Oct 12 '22 06:10

Tomalak