0

I have a column box_coordinates of type integer[4] and I want to divide each element of the array by 640 and insert it into a new column of type float[4]. I first try to divide each element of the array before aggregating

SELECT n/640::float
FROM (
    SELECT unnest(box_coordinates) 
    FROM images 
) AS n;

but it fails with error

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.

How do I apply the array element division and then insert the result into a new column of type float[4], while keeping the order of the elements in the new array unchanged?

1 Answer 1

2

you are using n instead unnest result

SELECT n.coord/640::float
FROM (
    SELECT unnest(box_coordinates) as coord
    FROM images 
    LIMIT 4
) AS n;
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that works! Could you please edit your post to answer how you would insert it to a new column of type float[4]?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.