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}}
2
  • Thank you for helping me. I need different dimension. Is it possible to have it?
    – DarkCoffee
    Commented Aug 4, 2013 at 14:42
  • 2
    @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. Commented Aug 4, 2013 at 15:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.