ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)

Поиск
Список
Период
Сортировка
От Michael Herold
Тема ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)
Дата
Msg-id 559DC0CE.90900@hemio.de
обсуждение исходный текст
Ответы Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-docs
A few minutes ago I got bitten by the following PostgreSQL (9.4) behavior

SELECT ARRAY[1] || NULL, array_append(ARRAY[1], NULL);
  ?column? | array_append
----------+--------------
  {1}      | {1,NULL}

I expected that array_append and || are equivalent in this case but
obviously they are not. Sure, this is not too surprising since "||" has
to guess which operation is appropriate. However, I would have highly
appreciated ARRAY[1,2] || NULL as an example in [Table 9-45]. Combined
with the example of NULL || ARRAY[1,2] the underlying principle becomes
clear to me.

Strings behave different, but maybe this is also a potential pitfall:

SELECT 'abc' || NULL, concat('abc', NULL);
  ?column? | concat
----------+--------
  (NULL)   | abc

Best,
Michael

[Table 9-45]:
<http://www.postgresql.org/docs/9.4/static/functions-array.html#ARRAY-OPERATORS-TABLE>


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

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Re: Outdated note about unique indexes
Следующее
От: Tom Lane
Дата:
Сообщение: Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)