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