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


select
    c.id as contract_id,
    c.number as contract_number,
    p.id as product_id,
    p.name as product_name,
    pppp.param_pl_id,
    pppp.value_ref,
    prod_line.get_value_link_param(
        pp.id::integer,
        pppp.value_ref::integer
    ) as guarantee_replenishment_period
from ourpension.contract c
join ourpension.contract_product_history h
    on h.contract_id = c.id
   and current_timestamp between
       h.begin_date and coalesce(h.end_date, 'infinity')
join prod_line.pens_product p
    on p.id = h.pens_product_id
join prod_line.pens_product_param_pl pppp
    on pppp.pens_product_id = p.id
join prod_line.param_pl pp
    on pp.id = pppp.param_pl_id
where c.service_type in ('NPO', 'PDS')
  and pp.brief = 'ПериодГарантВосполнения'
  and pppp.value_ref is not null
limit 20;