postgresqlpostgresql-15

How compare value of BIT column?


I have a bit column (for example, 'Column').

How can I compare the value of this column to just any number?

SELECT * FROM TABLE WHERE 'Column' = 5

After executing the above query, I get an error message: the operator does not exist: bit = integer


Solution

  • You can convert the value to compre to bit

    CREATE TABLE TABLE_1 (Column1 bit(4))
    
    CREATE TABLE
    
    SELECT * FROM TABLE_1 WHERE Column1 = 5::BIT(4)
    
    column1
    SELECT 0
    

    fiddle