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>


--
Sent via pgsql-docs mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-docs

Reply via email to