Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.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
Sql 使用列更新集,具体取决于其他列_Sql_Postgresql_Sql Update - Fatal编程技术网

Sql 使用列更新集,具体取决于其他列

Sql 使用列更新集,具体取决于其他列,sql,postgresql,sql-update,Sql,Postgresql,Sql Update,我正在尝试设置列值,例如area,然后在以下集合中使用此area列值,例如area*somecolumn。当我这样做时,似乎还没有设置区域。我需要为postgres做些什么来注册/理解/提交下一个set语句吗?还是应该这样做 update table1 t1 set area = something; --update/commit/save edits/? update table1 t1 set volume = area * col1 #I belive area

我正在尝试设置列值,例如
area
,然后在以下集合中使用此
area
列值,例如
area*somecolumn
。当我这样做时,似乎还没有设置
区域
。我需要为postgres做些什么来注册/理解/提交下一个set语句吗?还是应该这样做

update table1 t1
set
    area = something;
    --update/commit/save edits/?

update table1 t1
set
    volume = area * col1 #I belive area hasnt been set yet so volume become NULL. But when I look at the table afterwards, area has a value

and many more...

您的查询应该按照您的意愿执行,前提是“something”和
col1
不是
null

但是,只需一句话,您就可以轻松做到:

update table1 t1
set area = $1, volume = $1 * col1

很好,那我一定是做错了什么,我会努力找出原因的。美元符号代表什么?@BERA:这是一个绑定参数,表示要传递给查询的值(您在问题中称之为“某物”)。美元符号用于按各自的顺序引用输入参数。@BERA:我明白了。这叫做整数除法。注意:我建议使用精确的数据类型(
numeric
decimal
),而不是不精确的
real
。@BERA:是的。如果有一个数值操作数,则整个操作将在数值上下文中执行。