Re: [GENERAL] Surprising results from array concatenation

От: Tom Lane
Тема: Re: [GENERAL] Surprising results from array concatenation
Дата: ,
Msg-id: 24303.1493142797@sss.pgh.pa.us
(см: обсуждение, исходный текст)
Ответ на: Re: [GENERAL] Surprising results from array concatenation  ("David G. Johnston")
Ответы: Re: [GENERAL] Surprising results from array concatenation  (Mike Blackwell)
Список: pgsql-general

Скрыть дерево обсуждения

[GENERAL] Surprising results from array concatenation  (Mike Blackwell, )
 Re: [GENERAL] Surprising results from array concatenation  ("David G. Johnston", )
  Re: [GENERAL] Surprising results from array concatenation  (Tom Lane, )
   Re: [GENERAL] Surprising results from array concatenation  (Mike Blackwell, )

"David G. Johnston" <> writes:
> On Tue, Apr 25, 2017 at 9:26 AM, Mike Blackwell <>
> wrote:
>> The docs (section 9.18 for PG 9.6) show as an example for array
>> concatenation
>> ARRAY[4,5,6] || 7
>> which works fine.  However, trying the same with an array of text doesn't
>> work:
>> # select array['a','b','c'] || 'd';
>> ERROR:  malformed array literal: "d"
>>
>> The assumption that the second argument is an array constant seems
>> surprising

> ​It has to assume something.  And for better and worse it has to assume it
> without looking at the actual value.

Yeah.  The core problem here is that the parser has to disambiguate the
|| operator: is it "anyarray || anyelement" or "anyarray || anyarray"?
In your first example the array can be seen to be int[] and 7 is taken
to be type int, so only "anyarray || anyelement" works.  In the second
case it's looking at "int[] || unknown", and the relevant heuristic is
to assume that the "unknown" is the same type as the operator's other
input.

Peeking at the contents of the literal would make the behavior very
unpredictable/data-dependent, so we don't.

            regards, tom lane



В списке pgsql-general по дате сообщения:

От: Andy Colson
Дата:
Сообщение: Re: [GENERAL] pg_test_fsync performance
От: Glen Huang
Дата:
Сообщение: [GENERAL] Questions regarding JSON processing