I'd like to do the following:
CREATE TABLE example ( name text, arr text[][]);
INSERT INTO example VALUES ( 'aa', '{}');
UPDATE example SET arr = arr || ARRAY['header'] WHERE name = 'aa';
Right here, I have arr = [['header']]
. I can easily add another array making it arr = [['header'], ['another']]
by calling the last line from above again with 'another' inside the array constructor. However, I'm looking to add elements to those inner arrays now. Something like...
UPDATE example SET version[1] = version[1] || ARRAY['more'] WHERE name = 'aa'
However, postgres throws the error, wrong number of subscripts. I understand that postgres multidimensional arrays must have the same dimensions inside, so I would have to be able to add an element to all the inner arrays at once (probably NULL) and then change the one I'm adding to. Is there any way to do this without some kind of loop?