Загрузка данных


select
    h.contract_id,
    c.number,
    h.pens_product_id,
    pppp.id as product_param_id,
    link.hb_param_pl_multiselect_id as product_vesting_type_id,
    ms.name as product_vesting_type
from ourpension.contract_product_history h
join ourpension.contract c
    on c.id = h.contract_id
left join ourpension.contract_params cp
    on cp.contract_id = h.contract_id
join prod_line.pens_product_param_pl pppp
    on pppp.pens_product_id = h.pens_product_id
   and pppp.param_pl_id = 4443
join prod_line.pens_product_param_pl_hb_param_pl_multiselect link
    on link.pens_product_param_pl_id = pppp.id
join prod_line.hb_param_pl_multiselect ms
    on ms.id = link.hb_param_pl_multiselect_id
where cp.account_vesting_type_id is null
  and current_timestamp between
      h.begin_date
      and coalesce(h.end_date, 'infinity')
order by h.contract_id desc
limit 20;