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


select
    h.contract_id,
    c.number,
    h.pens_product_id,
    cp.account_vesting_type_id
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
where h.pens_product_id = 9627
  and 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;