错误:用作表达式的子查询返回的多行

时间:2016-03-15 23:45:46

标签: database postgresql postgis

我正在开发一个asp.net数据,我会在一列中插入数据。但他在另一行发送了我能做些什么来纠正这个问题?它发送给我:错误:用作表达式

的子查询返回的多行
  

错误

     

错误:用作表达式的子查询返回多行   SQL状态:21000

UPDATE accident_ma
  SET geom_acc = (
    SELECT ST_Line_Interpolate_Point (route.geom, ( 
      select (pk_accident)/(pk_fin-pk_debut)
      from route, accident_ma 
      where route.num_route = accident_ma.num_route
      order by route.num_route limit 1))
    from route, accident_ma 
    where route.num_route = accident_ma.num_route
    order by route.num_route)
  from route
  where route.gid = accident_ma.gid;

1 个答案:

答案 0 :(得分:2)

在我看来,你使事情变得非常困难。即使accident_ma上有route.geom的多个事件,下面的内容也可以正常使用:

UPDATE accident_ma a
  SET geom_acc = ST_Line_Interpolate_Point(r.geom, a.pk_accident / (a.pk_fin-a.pk_debut))
  FROM route r
  WHERE a.num_route = r.num_route
    AND a.gid = r.gid;

在您的代码中,当单个路径上发生多起事故时,相关子查询将返回多行。在这个不会发生的解决方案中:每个UPDATE都会在一次事故中运作。