我有一个整数[4]类型的box_coordinates,我想将数组的每个元素除以640并将其插入float [4]类型的新列中。我首先尝试在聚合
之前划分数组的每个元素SELECT n/640::float
FROM (
SELECT unnest(box_coordinates)
FROM images
) AS n;
但失败并显示错误
ERROR: operator does not exist: record / integer
HINT: No operator matches the given name and argument type(s).
You might need to add explicit type casts.
如何应用数组元素除法然后将结果插入到float [4]类型的新列中,同时保持新数组中元素的顺序不变?
答案 0 :(得分:2)
您正在使用n
而不是unnest
结果
SELECT n.coord/640::float
FROM (
SELECT unnest(box_coordinates) as coord
FROM images
LIMIT 4
) AS n;