0

Let's say I have a table in postgresql called 'Test' which contains a single column called 'Column1' of the type int[]. So, it can contain an array of integers for each row, for example, {1,2,3}. I want to know if it is possible to insert an array of arrays in a table in postgresql, like {{1,2,3},{1,3,5},{9,10}} in a single cell of a table in postgresql? If so then what should be the datatype of the column, and how can we achieve that?

0
create table test (id int [])
insert into test values ( ARRAY [1,2,3] )
1 rows affected
insert into test values ( ARRAY [ARRAY [1,2,3],ARRAY [1,2,4],ARRAY [1,2,5]] )
1 rows affected
select * from test
| id                        |
| :------------------------ |
| {1,2,3}                   |
| {{1,2,3},{1,2,4},{1,2,5}} |

db<>fiddle here

Really - multi-dimentional array is formed.


I want to know if it is possible to insert an array of arrays in a table in postgresql, like {{1,2,3},{1,3,5},{9,10}} in a single cell of a table in postgresql?

No. 3rd element have 2 elements whereas first two have 3 elements. The error message

ERROR: multidimensional arrays must have array expressions with matching dimensions

will be produced.

But different dimensions in different records are allowed.

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.