JohnSmith
JohnSmith

Reputation: 4688

how to perform a bitwise operator on result in postegres?

If I have several rows, and I would like to perform a bitwise OR on the result, how can I do this in Postgres 9.x ?

e.g. my table contains

Name col1 col2
--------------
John    1    2
Walter  1    1
Ron     1    2

I know would like to perform select statements so that I get OR of all (or a subset of) values from a column.

E.g.

select [magical statement OR col1] from table
would give me
1

select [magical statement OR col2] from table
would give me
3

I hope you can understand what I mean, I cant figure out what the proper term is for what I want.

Upvotes: 4

Views: 481

Answers (1)

Francisco Soto
Francisco Soto

Reputation: 10392

select bit_or(col1) from table group by col1;

Reference (it may not be present in your version, so check the documentation):

Aggregate functions - PostgreSQL documentation.

Upvotes: 4

Related Questions