select
h.pens_product_id,
pppp.id as product_param_id,
pp.id as param_id,
pp.name as param_name,
pp.brief,
pppp.value_ref,
ms.name as value_name
from ourpension.contract_product_history h
join prod_line.pens_product_param_pl pppp
on pppp.pens_product_id = h.pens_product_id
join prod_line.param_pl pp
on pp.id = pppp.param_pl_id
left join prod_line.hb_param_pl_multiselect ms
on ms.id = pppp.value_ref
where h.contract_id = 13063250
and current_timestamp between
h.begin_date
and coalesce(h.end_date, 'infinity')
and lower(ms.name) in ('кипс', 'ипс')
order by pppp.id;