Original query:

select pu.owner_id, pus.id, pu.old_valid_to, pu.valid_from, pu.new_valid_to, is_possession, pus.expire_date from payments_uslog pu join payments_priceprofileversion ppv on pu.priceprofileversion_id = ppv.id join payments_pricegroup pg on pg.code = ppv.pricegroup_id join payments_usersubscription pus on pus.id = pu.usersubscription_id where pg.code = 'CI' and new_valid_to::date > '2020-08-31' and pus.expire_date > '2020-08-31' and pu.new_valid_to != pus.expire_date;