Вам нужна динамическая команда . Функция должна выполнять работу:
create or replace function eval_condition(attr text, a_type text, op text, val text)
returns boolean language plpgsql immutable as $$
declare
result boolean;
begin
execute format(
'select %L::%s %s %L::%s',
attr, a_type, op, val, a_type)
into result;
return result;
end $$;
Примеры:
with example(attr, a_type, op, val) as (
values
('100', 'int', '>', '50'),
('2019-01-01', 'date', '>', '2019-01-02'),
('some text', 'text', 'like', 'some%'),
('99.99', 'numeric', '<', '99.99')
)
select
attr, a_type, op, val,
eval_condition(attr, a_type, op, val)
from example;
attr | a_type | op | val | eval_condition
------------+---------+------+------------+----------------
100 | int | > | 50 | t
2019-01-01 | date | > | 2019-01-02 | f
some text | text | like | some% | t
99.99 | numeric | < | 99.99 | f
(4 rows)