Search code examples
sqlpostgresqlintegerbigintegerunsigned

XOR between numeric in PostgreSQL


So I have two integers > 2 ^ 63 - 1 but < 2 ^ 64 -1. This is BIGINT UNSIGNED in most languages, but according to Comparison of database column types in MySQL, PostgreSQL, and SQLite? (Cross-Mapping), its numeric(20) in postogresql

problem is, when I try to do a postgresql xor operation between two unsigned bigints:

select 17418945696623429624::numeric(20) # 17418945696623429624::numeric(20);

=>

ERROR:  operator does not exist: numeric # numeric

with any non "numeric" integer less than 2 ^ 63 -1, it works fine.

rephrase: How can I perform a XOR operation between two numbers larger than 2 ^ 63 - 1 but less than 2 ^ 64 - 1? Ex. How can I XOR 17418945696623429624 with itself in PostgreSQL?


Solution

  • Looks like PostgreSQL has a bigint type-- why don't you use that?