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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.

Comments

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.