Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对PostgreSQL中数组类型列中的每个元素应用除法_Sql_Postgresql - Fatal编程技术网

对PostgreSQL中数组类型列中的每个元素应用除法

对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

我有一个整型[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 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()