Skip to main content

array_append

1. ARRAY_APPEND Function

The ARRAY_APPEND function in H2 database is used to append an element to the end of an array.

2. Syntax

The syntax for the ARRAY_APPEND function in H2 database is as follows:

ARRAY_APPEND(array, element)

Arguments

  • array: The array to which the element needs to be appended.
  • element: The element that needs to be appended to the array.

Return

  • The ARRAY_APPEND function returns a new array with the specified element appended at the end.

3. Notes

  • The ARRAY_APPEND function in H2 database is useful when you want to add an element to an existing array without modifying the original array.
  • The input array should be of a compatible data type. If the array is empty or NULL, the function will return an array containing only the appended element.
  • If the input array is NULL, the function will return NULL.
  • The ARRAY_APPEND function is available in H2 version 1.4.200 and above.

4. Examples

Here are a few examples demonstrating the usage of the ARRAY_APPEND function in H2 database:

Example 1 - Appending an element to an array:

SELECT ARRAY_APPEND(ARRAY[1, 2, 3], 4) AS new_array;

Output:

new_array
-----------------
[1, 2, 3, 4]

Example 2 - Appending an element to an empty array:

SELECT ARRAY_APPEND(ARRAY[], 'Hello') AS new_array;

Output:

new_array
---------
['Hello']

Example 3 - Appending an element to a NULL array:

SELECT ARRAY_APPEND(NULL, 123) AS new_array;

Output:

new_array
---------
NULL
  • ARRAY_CONCAT - Concatenate arrays
  • ARRAY_INSERT - Insert element at a specific position in an array