1

I have a table that contains binary values such as:

binaryid    description
1           description1
2           description2
4           description3
8           description4

And I have another table that contains values:

DBID BinaryTogether
1    15
1    12
1     6

With the bitwise operator I want to get a table that would contain the following:

DBID   BinaryTogether BitwiseResult
1      15             description1,description2,description3,description4
1      12             description3,description4
1       6             description2, description3
1

1 Answer 1

1

You can join those tables using & bitwise operator and then aggregate descriptions using string_agg function. Here is example:

with 
  b(x,d) as (
    values
      (1,'description1'),
      (2,'description2'),
      (4,'description3'),
      (8,'description4')),
  p(y) as (
    values
      (15),
      (12),
      (6))
select
  y,
  string_agg(d,',')
from
  p join b on (x & y != 0)
group by
  y
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.