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:是的。如果有一个数值操作数,则整个操作将在数值上下文中执行。