Tom Lane wrote:
Joe Conway <[EMAIL PROTECTED]> writes:
Sorry for the slow response -- I'm at the airport just heading home from a marathon 30 day business trip.

Yow.  Hope you get some time off...

Yeah, I just took a week. Next week I'm back to work and the week after that I'm back to Germany for a few...

On looking at the code, I notice that this somewhat-related case works:

regression=# select array[null::text[], null::text[]];
 array
-------
 {}
(1 row)

The reason is that null inputs are just ignored in ExecEvalArray.  So
one pretty simple patch would be to ignore zero-dimensional inputs too.
This would have implications for mixed inputs though: instead of

regression=# select array['{}'::text[], '{a,b,c}'::text[]];
ERROR:  multidimensional arrays must have array expressions with matching 
dimensions

you'd get behavior like

regression=# select array[null::text[], '{a,b,c}'::text[]];
   array
-----------
 {{a,b,c}}
(1 row)

Which of these seems more sane?

I'm not sure I love either. I would think both NULL and empty array expressions should be disallowed in this scenario, i.e.:

        regression=# select array['{}'::text[], '{a,b,c}'::text[]];
ERROR: multidimensional arrays must have array expressions with matching dimensions

        regression=# select array[NULL::text[], '{a,b,c}'::text[]];
        ERROR:  multidimensional arrays must have array expressions with
        matching dimensions

In both cases you are trying to construct a multidimensional array with inconsistent dimensions.

On the other hand, building an N-dimension array from entirely empty array expressions should just produce an empty array, while using all NULL expressions should produce an N-dim array full of NULLs.

But as I've opined before, all of this seems to me to be much cleaner if arrays were always one-dimensional, and array elements could also be nested arrays (per SQL 2003). If we said that the cardinality of the nested array is an integral part of the datatype, then I think you would have:

        regression=# select array['{}'::text[], '{a,b,c}'::text[]];
        ERROR:  nested arrays must have array expressions with matching
        dimensions

        regression=# select array[NULL::text[], '{a,b,c}'::text[]];
            array
         -----------
          {NULL, {a,b,c}}
         (1 row)

So maybe this is the behavior we should shoot for now?

Joe

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to