816
816
> supports multidimensional arrays.
818
Note that the concatenation operator discussed above is preferred over
819
direct use of these functions. In fact, these functions primarily exist for use
820
in implementing the concatenation operator. However, they might be directly
821
useful in the creation of user-defined aggregates. Some examples:
824
820
CLASS="PROGRAMLISTING"
852
848
{{5,6},{1,2},{3,4}}</PRE
852
> In simple cases, the concatenation operator discussed above is preferred
853
over direct use of these functions. However, because the concatenation
854
operator is overloaded to serve all three cases, there are situations where
855
use of one of the functions is helpful to avoid ambiguity. For example
859
CLASS="PROGRAMLISTING"
860
>SELECT ARRAY[1, 2] || '{3, 4}'; -- the untyped literal is taken as an array
865
SELECT ARRAY[1, 2] || '7'; -- so is this one
866
ERROR: malformed array literal: "7"
868
SELECT ARRAY[1, 2] || NULL; -- so is an undecorated NULL
874
SELECT array_append(ARRAY[1, 2], NULL); -- this might have been meant
880
In the examples above, the parser sees an integer array on one side of the
881
concatenation operator, and a constant of undetermined type on the other.
882
The heuristic it uses to resolve the constant's type is to assume it's of
883
the same type as the operator's other input — in this case,
884
integer array. So the concatenation operator is presumed to
892
that's the wrong choice, it could be fixed by casting the constant to the
893
array's element type; but explicit use of <CODE
897
be a preferable solution.