Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql postgres中的动态计算_Postgresql_Postgresql 9.1_Postgresql 9.2_Postgresql 8.4 - Fatal编程技术网

Postgresql postgres中的动态计算

Postgresql postgres中的动态计算,postgresql,postgresql-9.1,postgresql-9.2,postgresql-8.4,Postgresql,Postgresql 9.1,Postgresql 9.2,Postgresql 8.4,我想在研究生阶段做一个动态计算 如下 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::numeri

我想在研究生阶段做一个动态计算

如下

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'(因为我的计算逻辑是id 1的表计算表中的$2-$1,其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

现在还不清楚你想做什么。你能更详细地解释这个问题,包括预期的结果吗?@hgmnz我编辑了我的帖子,让我的问题更清楚。你现在可以看一下吗。谢谢你不能只是把一段数学放在一列中,然后期望数据库为你计算它;您需要在某个地方告诉它“执行此语句”。也许你真正需要的是一个?不知道你是如何得到那个错误的;我刚刚得到的
类型numeric的输入语法无效:“$1-$2”
。请注意,您不希望在
select
语句中使用括号;他们会把结果变成一个“记录”,我很怀疑你的意图;我不确定你到底需要做什么,所以这并不是一个真正的答案: