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


select
    cp.contract_id,
    c.number as contract_number,
    f.contract_type,
    cp.payment_source_code,
    vst.label as payment_source
from ourpension.contract_params cp

join ourpension.contract c
    on c.id = cp.contract_id

cross join lateral ourpension.get_contract_fields_main(cp.contract_id) f

left join ourpension.voc_sharer_types vst
    on vst.code = cp.payment_source_code
   and vst.is_payment_source = true

where cp.payment_source_code is not null
  and f.contract_type = 'КПП'

order by cp.contract_id desc
limit 20;