[英]update table with 4 columns specified, but only 2 columns are available
我有一张表叫做test,它有4列:
id INT
v_out INT
v_in INT
label CHARACTER
我正在尝试使用以下查询更新表:
String sql = "
update
test
set
v_out = temp.outV
, v_in = temp.inV
, label = temp.label
from (
values(
(1,234,235,'abc')
,(2,234,5585,'def')
)
) as temp (e_id, outV, inV, label)
where
id = temp.e_id
";
当我执行它时,出现错误:
org.postgresql.util.PSQLException:错误:
table "temp" has 2 columns available but 4 columns specified
有什么问题,我该如何解决?
values
子句的values
不能用括号括起来:
values (
(1,234,235,'abc'), (2,234,5585,'def')
)
创建具有两列的单行。 每列都是具有4个字段的匿名“记录”。
您想要的是:
from (
values
(1,234,235,'abc'),
(2,234,5585,'def')
) as temp (e_id, outV, inV, label)
SQLFiddle显示差异: http ://sqlfiddle.com/#!15/d41d8/2763
此行为已记录在案,但很难找到:
http://www.postgresql.org/docs/current/static/rowtypes.html#AEN7362
select (col1, col2) from some_table
select col1, col2 from some_table
本质上是相同的。 第一个返回具有匿名复合类型的列,该复合类型具有两个字段。 第二个返回表中的两列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.