对PostgreSQL中数组类型列中的每个元素应用除法
我有一个整型[4]的列框_坐标,我想将数组的每个元素除以640,然后将其插入到float[4]类型的新列中。在聚合之前,我首先尝试对数组的每个元素进行分割对PostgreSQL中数组类型列中的每个元素应用除法,sql,postgresql,Sql,Postgresql,我有一个整型[4]的列框_坐标,我想将数组的每个元素除以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
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]类型的新列中,同时保持新数组中元素的顺序不变?您使用的是
n
而不是unest
result
SELECT n.coord/640::float
FROM (
SELECT unnest(box_coordinates) as coord
FROM images
LIMIT 4
) AS n;
您使用的是
n
而不是unest
结果
SELECT n.coord/640::float
FROM (
SELECT unnest(box_coordinates) as coord
FROM images
LIMIT 4
) AS n;
谢谢,行得通!请编辑您的帖子,回答如何将其插入float[4]类型的新列中?您需要
array\u agg()
谢谢,这很有效!请编辑您的帖子,回答如何将其插入float[4]类型的新列中?您需要array\u agg()