暂无图片
GBase 8a执行update SQL报错无法更新多行数据 can not update one row to multi-data
我来答
分享
暂无图片 匿名用户
GBase 8a执行update SQL报错无法更新多行数据 can not update one row to multi-data

报错样例


  1. gbase> create table t1(id int, value int);


  2. Query OK, 0 rows affected (Elapsed: 00:00:00.18)



  3. gbase> insert into t1 values(1,'0');


  4. Query OK, 1 row affected (Elapsed: 00:00:00.07)



  5. gbase> create table t2(id int, value int);


  6. Query OK, 0 rows affected (Elapsed: 00:00:00.10)



  7. gbase> insert into t2 values(1,123);


  8. Query OK, 1 row affected (Elapsed: 00:00:00.07)



  9. gbase> insert into t2 values(1,234);


  10. Query OK, 1 row affected (Elapsed: 00:00:00.07)



  11. gbase> select * from t1;


  12. +------+-------+


  13. | id | value |


  14. +------+-------+


  15. | 1 | 0 |


  16. +------+-------+


  17. 1 row in set (Elapsed: 00:00:00.00)



  18. gbase> select * from t2;


  19. +------+-------+


  20. | id | value |


  21. +------+-------+


  22. | 1 | 123 |


  23. | 1 | 234 |


  24. +------+-------+


  25. 2 rows in set (Elapsed: 00:00:00.01)



  26. gbase> update t1 set value=(select value from t2 where t2.id=t1.id);


  27. ERROR 1709 (HY000): [10.0.2.107:5050](GBA-02AD-0005)Failed to query in gnode:


  28. DETAIL: (GBA-01EX-0002) Subquery return more than 1 row


  29. SQL: /*::ffff:10.0.2.107_118_18_2020-09-03_20:47:02*/ UPDATE `testdb`.`t1_n1` `testdb.t1` SET `testdb.t1`.`value` = ( SELECT `testdb.t2`.`value` as `value` From `gctmpdb`.`_tmp_1795293194_118_t51_1_1599096136_s` `testdb.t2` WHERE (`testdb.t2`.`id` = `testdb.t1`.`id`));


  30. gbase> update t1,t2 set t1.value=t2.value where t1.id=t2.id;


  31. ERROR 1709 (HY000): [10.0.2.107:5050](GBA-02AD-0005)Failed to query in gnode:


  32. DETAIL: (GBA-01EX-700) Gbase general error: can not update one row to multi-data


  33. SQL: /*::ffff:10.0.2.107_118_19_2020-09-03_20:47:28*/ UPDATE `gctmpdb`._tmp_1795293194_118_t52_1_1599096136_s INNER JOIN `testdb`.`t1_n1` `testdb.t1` ON (`testdb.t1`.`id` = `_tmp_1795293194_118_t52_1_1599096136_s`.`id`) SET `testdb.t1`.`value` = `_tmp_1795293194_118_t52_1_1599096136_s`.`testdb.t1.value`;


  34. gbase>


  35. ```bash





```

我来答
添加附件
收藏
分享
问题补充
1条回答
默认
最新
生命之源

首先从业务上要避免这种1:n更新的情况。

如果实在避免不了,对于子查询,可以用limit限定结果集。比如

  1. gbase> update t1 set value=(select value from t2 where t2.id=t1.id limit 1);

  2. Query OK, 1 row affected (Elapsed: 00:00:00.28)

  3. Rows matched: 1 Changed: 1 Warnings:

  4. gbase> select * from t1;

  5. +------+-------+

  6. | id | value |

  7. +------+-------+

  8. | 1 | 234 |

  9. +------+-------+

  10. 1 row in set (Elapsed: 00:00:00.00)




对于多表关联更新,无解。请调整业务或改写SQL。

暂无图片 评论
暂无图片 有用 1
回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
暂无图片墨值悬赏