2

I'm trying to replicate a function that a former employee built within Postgres in another language and having trouble working out what the # operator does. I've run a few numbers through it and there doesn't seem to be any consistency in the results:

select  1 # 1  --0
        ,1 # 2 --3
        ,1 # 3 --2
        ,1 # 4 --5
        ,1 # 5 --4
        ,2 # 2 --0
        ,2 # 3 --1
        ,2 # 4 --6

If anyone is able to explain I would be hugely grateful!

Rossy
  • 65
  • 1
  • 6

1 Answers1

5

Officially it's called "bitwise XOR". See 9.6. Bit String Functions and Operators.

It computes a XOR operation between each bit of the two counterparts.

For example:

select 10 # 12

Would be computed as a XOR between their corresponding binary digits:

1 0 1 0 (decimal 10)
1 1 0 0 (decimal 12)
-------
0 1 1 0 (decimal 6)

Result:

6
The Impaler
  • 45,731
  • 9
  • 39
  • 76