select
pppp.pens_product_id,
pppp.id as product_param_id,
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 prod_line.pens_product_param_pl pppp
join prod_line.param_pl pp
on pp.id = pppp.param_pl_id
where pp.brief = 'ТипВыплаты'
and (
pppp.value_ref is not null
or pppp.value_int is not null
or pppp.value_decimal is not null
or pppp.value_string is not null
)
order by pppp.pens_product_id desc
limit 50;