Translate this MySQL query to PyGreSQL

I am working on a Ruby application that uses the mysql functions XOR (^) and BIT_COUNT (). However, now I need to run an application on Heroku that runs PyGreSQL.

I cannot find documentation for PyGreSQL bits that can help me.

So, can anyone translate this mysql query so that it works when executed in pygresql?

SELECT * FROM "photos" WHERE BIT_COUNT(phash ^ 2061756291569501157) <= 15

pygresql gives me an error

ERROR:  operator does not exist: text ^ bigint

thank.

+1
source share
1 answer
SELECT  *
FROM    photos
WHERE   (
        SELECT  SUM(((phash::bigint # 2061756291569501157) >> bit) & 1)
        FROM    generate_series(0, 63) bit
        ) <= 15
+2
source

All Articles