Re: BUG #2212: Extracting array from 2 dim array may be incorrect

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #2212: Extracting array from 2 dim array may be incorrect
Дата
Msg-id 19963.1138296489@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #2212: Extracting array from 2 dim array may be incorrect  ("Walter Roeland" <wroeland@marcatel.net>)
Список pgsql-bugs
"Walter Roeland" <wroeland@marcatel.net> writes:
> Select (Array[5,8,1])[2] as E;
> returns 8 (ok, dimension is lowerd from 1 to 0).

> Select (Array[Array[3,2,2],Array[7,4,4],Array[5,8,1]])[3:3] as V;
> returns {{5,8,1}} (I suppose this is ok, same dimension).

> But:
> Select (Array[Array[3,2,2],Array[7,4,4],Array[5,8,1]])[3] as V;
> Returns Null, as far I understand it should return {5,8,1}, i.e. lowering
> dimension from 2 to 1.

The current rule is that if you write an array slice subscript (ie,
use ":" in at least one of the subscripts), you get an array out.
If you don't write ":", you get a single element out.  We cannot
really change this on-the-fly, because the result type of the
expression has to be determinable at parse time.  (If the exact number
of dimensions of an array were part of its type signature, we could
do what you're imagining, but it's not: all arrays over the same base
type have the same type, and dimensionality is strictly a run-time
thing.)

I can see the argument for raising an error, instead of returning NULL,
when the number of subscripts isn't compatible with the number of
dimensions.  But I'm not sure it's worth taking any
backward-compatibility risks for...

            regards, tom lane

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #2215: Cannot restore backup cause of view's representaion
Следующее
От: Tom Lane
Дата:
Сообщение: Re: BUG #2195: log_min_messages crash server when in DEBUG3 to