2

I'm working with a problem similar to this one: PostgreSQL: concatenate nested arrays with differing element dimensions

In this problem, a user wants to be able to create a multi-dimensional array like:

{{1,2},{3}}

using something like:

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

Erwin Brandsetter says it's not possible without a cheap trick like padding with some dummy value.

I'm wondering if I can approach this problem in a different way to construct a multi-dimensional array. Or some equivalent structure that's basically the same thing. Like constructing some data type to replace the int[] structure. Or possibly use the postgres json feature.

I would preferably like the solution to allow for easy appending/ replacing. Multidimensional array manipulation so far hasn't been fun in postgresql.

2 Answers 2

4

Probably jsonb is only one possible solution to multidimensional arrays with different dimension of array.

1
  • 1
    Thank you. I did decide to go down the jsonb road and it seemed possible but gave up and wrote what I wanted to do in python/psychopg2.
    – agent nate
    Jul 26, 2018 at 1:13
0

Simple response - PostgreSQL has not array of arrays type. It is not dynamic type (collection) based system. Probably the user is on wrong way with no end. There is not any simple solution. Maybe you should to use different application or you should to change you mind to be more relational.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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