Re: casting strings to multidimensional arrays yields strange results - Mailing list pgsql-bugs

From Tom Lane
Subject Re: casting strings to multidimensional arrays yields strange results
Date
Msg-id 28217.1090937292@sss.pgh.pa.us
Whole thread Raw
In response to casting strings to multidimensional arrays yields strange results  (Kris Jurka <books@ejurka.com>)
Responses Re: casting strings to multidimensional arrays yields strange
List pgsql-bugs
Kris Jurka <books@ejurka.com> writes:
> Casting strings to multidimensional arrays yields strange results.

array_in has fairly bizarre behavior when presented with non-rectangular
input data, such as your examples:

> jurka=# SELECT '{{1,2},{2,3},{4}}'::int[][];

> jurka=# SELECT '{{1},{2,3},{4,5}}'::int[][];

I don't recall the details right now of how it chooses the actual array
dimensions, but it's weird.  I've been tempted to rewrite it but have
refrained for fear of breaking existing applications.  Also, it's not
entirely clear what the behavior *should* be.

Right now I think the sanest behavior would be to throw an error on
non-rectangular input.  Once we have support for null elements in
arrays, however, it would arguably be reasonable to pad with NULLs
where needed, so that the above would be read as

    {{1,2},{2,3},{4,NULL}}

    {{1,NULL},{2,3},{4,5}}

respectively.  If that's the direction we want to head in, it would
probably be best to leave array_in alone until we can do that; users
tend to get unhappy when we change behavior repeatedly.

What's your thoughts?

            regards, tom lane

pgsql-bugs by date:

Previous
From: Kris Jurka
Date:
Subject: Re: casting strings to multidimensional arrays yields strange
Next
From: Joe Conway
Date:
Subject: Re: casting strings to multidimensional arrays yields strange