array bad behavior?

Started by Thalis A. Kalfigopoulosalmost 25 years ago2 messagesgeneral
Jump to latest
#1Thalis A. Kalfigopoulos
thalis@cs.pitt.edu

I create the following table:
create table lala (id int,people varchar(10)[][]);

I insert as follows:
insert into lala values(1000,'{{"1_1","1_2"},{"2_1","2_2"}}');

Works just fine:
id | people
------+----------------------------
1000 | {{"1_1","1_2"},{"2_1","2_2"}}

Then I insert:
insert into lala values(1002,'{{"1_1"},{"2_1","2_2"}}');

Which behaves well i.e. for the first row it fills in an empty string for the missing element (2D array has to be NxN):
id | people
------+----------------------------
1000 | {{"1_1","1_2"},{"2_1",""}}
1002 | {{"1_1",""},{"2_1","2_2"}}

Then I insert:
insert into lala values(1003,'{{"1_1","1_2"},{"2_1"}}');

Which doesn't work exactly as expected, i.e. it doesn't fill in the missing element of the second row with an empty string as it did earlier, but instead truncates the first row to match the size of the second:
id | people
------+-------------------------------
1000 | {{"1_1","1_2"},{"2_1","2_2"}}
1002 | {{"1_1",""},{"2_1","2_2"}}
1003 | {{"1_1"},{"2_1"}}

Is that normal?

thanks in advance,
thalis

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Thalis A. Kalfigopoulos (#1)
Re: array bad behavior?

"Thalis A. Kalfigopoulos" <thalis@cs.pitt.edu> writes:

Then I insert:
insert into lala values(1003,'{{"1_1","1_2"},{"2_1"}}');

IIRC, the array code is fairly buggy for non-rectangular arrays.
The array parser doesn't really do these correctly, and even if it
did, the *right* behavior IMHO would be to fill the missing elements
with NULLs, which can't be done yet because the array representation
doesn't handle NULL elements.

Someone needs to work on it --- want to volunteer?

regards, tom lane