Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Concatenating the nested arrays {{1,2}} and {{3,4}} is no problem at all:

SELECT array_cat(
           ARRAY[ARRAY[1,2]]
         , ARRAY[ARRAY[3,4]]
       )

   array_cat   
---------------
 {{1,2},{3,4}}

But how to concatenate {{1,2}} and {{3}} in order to get {{1,2},{3}}?

SELECT array_cat(
           ARRAY[ARRAY[1,2]]
         , ARRAY[ARRAY[3]]
       )
psql: …: ERROR:  cannot concatenate incompatible arrays
DETAIL:  Arrays with differing element dimensions are not compatible
         for concatenation.
share|improve this question
    
What structure do you expect for the final array? {{1,2},{3}} ? –  Tony May 28 at 16:34
    
I've just updated the question. –  user3684490 May 28 at 16:35

1 Answer 1

up vote 0 down vote accepted

This is impossible in PostgreSQL. Multi-dimensional arrays must have the same number of element dimensions, just as the error message informs. Per documentation:

Multidimensional arrays must have matching extents for each dimension. A mismatch causes an error.

You might want to pad with NULL or some other dummy value ...

share|improve this answer
    
I've already feared that. Seems like I have to look for another approach for my application. –  user3684490 May 28 at 16:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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