ERROR: more than one row returned by a subquery used as an expression

ERROR: more than one row returned by a subquery used as an expression

我正在开发一个 asp.net 数据,我会在一列中插入一个数据。但他在另一条线上发送了它我可以做些什么来纠正这个问题?它发给我:错误:用作表达式的子查询返回多于一行

Error

ERROR: more than one row returned by a subquery used as an expression SQL state: 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;

我觉得你把事情复杂化了。即使在单个 route.geom 上有来自 accident_ma 的多个事件,以下内容也应该可以正常工作:

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;

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