1

I have a table with an attribute that is an array of arrays.

Example: a={{1,A, 1},{A,B,C},{45,46,47}}

I want to add an array to the array "a".

Example: new_array={Z,T} to "a" in order to have a={{Z,T},{1,A, 1},{A,B,C},{45,46,47}} `

I used the command: update test set a = ARRAY['Z','T'] || a;

but I got this error: No operator matches the given name and argument type(s). You might need to add explicit type casts.

So, I tried to add the ::text[] parameter in this way: update test set a = ARRAY['Z','T']::text[] || a::text[]; but there is still an error:

ERROR:  cannot concatenate incompatible arrays
DETAIL:  Arrays with differing dimensions are not compatible for concatenation.

Hence, my question is: how can I add the array to the array of arrays? .

1 Answer 1

2

To make them the same dimention add a null:

select '{{1,A, 1},{A,B,C},{45,46,47}}'::text[] || '{Z, T, null}';
                ?column?                 
-----------------------------------------
 {{1,A,1},{A,B,C},{45,46,47},{Z,T,NULL}}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for helping me. I need different dimension. Is it possible to have it?
@DarkCoffee No, Pg arrays need to be symmetric across the dimensions. They're not arrays of arrays, they are actual multidimensional arrays - think "like a matrix". They can't be sparse or short. It's to do with how the memory for them is managed internally and how they are accessed.

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.