postgresql:在列更新中分组 - 语法错误

postgresql: group by in column update - syntax error

我试图获取每个区域最高点的高度,我写了这个查询,它运行良好:

select max(obstacle.valhgt_ft) 
from obstacle,
     obstacle_buffer 
where st_contains (obstacle_buffer.geom,obstacle.geom) 
group by obstacle_buffer.primary_id

但是当我尝试使用此查询更新属性时,我在 "group"

附近遇到语法错误
UPDATE obstacle_buffer 
    SET max_valhgt_ft = max(obstacle.valhgt_ft) 
from obstacle,
     obstacle_buffer 
where st_contains (obstacle_buffer.geom,obstacle.geom) 
group by obstacle_buffer.primary_id

您尝试更新连接 table 但不允许您应该改用子查询

你可以做到这一点

UPDATE obstacle_buffer 
SET max_valhgt_ft = (select max(obstacle.valhgt_ft) 
                     from obstacle,obstacle_buffer 
                     where st_contains (obstacle_buffer.geom,obstacle.geom) 
                     group by obstacle_buffer.primary_id)

您可以使用相关子查询来执行此操作:

UPDATE obstacle_buffer 
    SET max_valhgt_ft = (select max(obstacle.valhgt_ft) 
                         from obstacle 
                         where st_contains (obstacle_buffer.geom, obstacle.geom))