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


select
    h.contract_id,
    h.pens_product_id,
    pppp.id as product_param_id,
    pp.id as param_id,
    pp.name,
    pp.brief,
    pppp.value_int,
    pppp.value_decimal,
    pppp.value_string,
    pppp.value_ref,
    prod_line.get_value_link_param(
        cast(pp.id as integer),
        cast(pppp.value_ref as integer)
    ) as payment_type
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
where h.contract_id = 13548911
  and current_timestamp between
      h.begin_date
      and coalesce(h.end_date, 'infinity')
  and pp.brief = 'ТипВыплаты';