Re: BUG #2694: Memory allocation error when selecting array

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: BUG #2694: Memory allocation error when selecting array
Дата
Msg-id 4544F95A.2020502@joeconway.com
обсуждение исходный текст
Ответ на Re: BUG #2694: Memory allocation error when selecting array  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: BUG #2694: Memory allocation error when selecting array  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
Tom Lane wrote:
> Joe Conway <mail@joeconway.com> 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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: "Magnus Hagander"
Дата:
Сообщение: Re: BUG #2712: could not fsync segment: Permission
Следующее
От: "Thomas H."
Дата:
Сообщение: Re: BUG #2712: could not fsync segment: Permission