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

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Vitali Stupin <Vitali(dot)Stupin(at)ria(dot)ee>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2694: Memory allocation error when selecting array
Date: 2006-10-29 18:56:26
Message-ID: 4544F95A.2020502@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Tom Lane wrote:
> Joe Conway <mail(at)joeconway(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Thomas H. 2006-10-29 20:21:05 Re: BUG #2712: could not fsync segment: Permission
Previous Message Magnus Hagander 2006-10-29 17:10:37 Re: BUG #2712: could not fsync segment: Permission