From: | Michael Herold <quabla(at)hemio(dot)de> |
---|---|
To: | pgsql-docs(at)postgresql(dot)org |
Subject: | ARRAY[1] || NULL <> array_append(ARRAY[1], NULL) |
Date: | 2015-07-09 00:31:10 |
Message-ID: | 559DC0CE.90900@hemio.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2015-07-09 14:00:57 | Re: ARRAY[1] || NULL <> array_append(ARRAY[1], NULL) |
Previous Message | Josh Berkus | 2015-07-08 22:10:46 | Re: Outdated note about unique indexes |