我正在尝试在postgres中进行动态计算
如下
drop table if exists calculation_t;
create table calculation_t(
Id serial,
calculation_logic varchar(50))
插入计算逻辑:
insert into calculation_t(calculation_logic)
values ('$1-$2')
通过提供动态数字2,1
来检查计算select (2,1,calculation_logic::numeric) from calculation_t
抛出错误:"错误:无法序列化瞬态记录类型"
我期待得到结果 通过选择
来'1' (because my calculation logic is $2-$1 from table caculation_t table for id 1, its 2-1)
select (2,1,calculation_logic::numeric) from calculation_t
也尝试过:
select replace(replace(calculation_logic, '$1', 2),'$2',1) from calculation_t
result :
"2-1"
But I needed 2-1 actual value from subtraction instead, that is 1