ARRAY[1] || NULL <> array_append(ARRAY[1], NULL) - Mailing list pgsql-docs

From Michael Herold
Subject ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)
Date
Msg-id 559DC0CE.90900@hemio.de
Whole thread Raw
Responses Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)
List 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 by date:

Previous
From: Josh Berkus
Date:
Subject: Re: Outdated note about unique indexes
Next
From: Tom Lane
Date:
Subject: Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL)