我有一个如下表:
point_path_id line_path_id season_id gps_time heading roll pitch geometry
1 ___ ___ ___ ___ ___ ___ PostGISGeom
2 ___ ___ ___ ___ ___ ___ PostGISGeom
3 ___ ___ ___ ___ ___ ___ PostGISGeom
4 ___ ___ ___ ___ ___ ___ PostGISGeom
5 ___ ___ ___ ___ ___ ___ PostGISGeom
在 PHP 中,我还拥有要更新的 ID 列表以及 line_path_id 和 season_id 的值。我也有用于 gps_time、heading、roll、pitch 的数组。
我有以下 SQL 语句(来自 PHP 的回显)
UPDATE greenland.point_paths
SET
line_path_id=1,
season_id=2,
gps_time=unnest(array[1303475178.0031,1303475178.0081,1303475179.0081,1303475180.0081,1303475181.0081]::double precision[]),
heading=unnest(array[-2.0819464,-2.0819407,-2.0820324,-2.08202,-2.0819855]::double precision[]),
roll=unnest(array[-0.007395,-0.007395,-0.0073832,-0.0073949,-0.0073853]::double precision[]),
pitch=unnest(array[-0.0246114,-0.0246115,-0.0246108,-0.024582,-0.0245905]::double precision[])
WHERE point_path_id IN (1,2,3,4,5);
这是插入,但不正确。数组的第一个值被插入到 point_path_id 中的所有 5 个 id。我在表中得到以下信息:
这种取消嵌套在许多其他语句中都可以正常工作,但我似乎无法让它以这种形式正常工作。我的错误在哪里?
以下是在此之前发生的事情的一些背景:通过 URLEAD(MATLAB) 发送 JSON 数据字符串,并通过 PHP 解码/插入到许多表中。
插入一个 PostGIS 线串 GEOM 并返回它的 ID (line_path_id) 插入一个季节并返回它的 ID (season_id)
然后将线串转储到上述表中的点中,并自动生成并返回串行 point_path_id。
然后需要插入与每个点相关的数据(这就是我想要做的)
我有每个点的 line_path_id、season_id、gps_time/heading/roll/pitch。时间/航向/滚动/俯仰在数组中是点数的长度。
可以有 100,000+ 点,但让我们用 5 来测试。
转储点后,此处再次显示一个表格:
point_path_id line_path_id season_id gps_time heading roll pitch geometry
1 ___ ___ ___ ___ ___ ___ PostGISGeom
2 ___ ___ ___ ___ ___ ___ PostGISGeom
3 ___ ___ ___ ___ ___ ___ PostGISGeom
4 ___ ___ ___ ___ ___ ___ PostGISGeom
5 ___ ___ ___ ___ ___ ___ PostGISGeom
我还有两个变量: $line_path_id = # $season_id = #
还有 4 个数组 $gps_time = [#,#,#,#,#]; 航向...滚动...俯仰...
我需要为每个点几何插入相关值。这是目标。
希望这有助于找到最佳解决方案。