Array Operators
Array comparison uses the default B-tree comparison function to compare all elements one by one. Elements of multi-dimensional arrays are accessed in row-major order. If the contents of two arrays are identical but their dimensionalities differ, the primary determinant of the sorting order is the dimensionality.
=
Description: Determines whether two arrays are equal.
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[1.1,2.1,3.1]::int[] = ARRAY[1,2,3] AS RESULT; result -------- t (1 row) |
<>
Description: Determines whether two arrays are not equal.
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[1,2,3] <> ARRAY[1,2,4] AS RESULT; result -------- t (1 row) |
<
Description: Determines whether one array is less than another array.
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[1,2,3] < ARRAY[1,2,4] AS RESULT; result -------- t (1 row) |
>
Description: Determines whether one array is greater than another array.
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[1,4,3] > ARRAY[1,2,4] AS RESULT; result -------- t (1 row) |
<=
Description: Determines whether one array is less than or equal to another array.
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[1,2,3] <= ARRAY[1,2,3] AS RESULT; result -------- t (1 row) |
>=
Description: Determines whether one array is greater than or equal to another array.
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[1,4,3] >= ARRAY[1,4,3] AS RESULT; result -------- t (1 row) |
@>
Description: Determines whether one array contains another array.
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[1,4,3] @> ARRAY[3,1] AS RESULT; result -------- t (1 row) |
<@
Description: Determines whether one array is contained within another array.
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[2,7] <@ ARRAY[1,7,4,2,6] AS RESULT; result -------- t (1 row) |
&&
Description: Determines whether one array overlaps with another array (shares common elements).
Example:
1 2 3 4 5 |
postgres=#SELECT ARRAY[1,4,3] && ARRAY[2,1] AS RESULT; result -------- t (1 row) |
||
- Description: Concatenates arrays.
1 2 3 4 5
postgres=#SELECT ARRAY[1,2,3] || ARRAY[4,5,6] AS RESULT; result --------------- {1,2,3,4,5,6} (1 row)
1 2 3 4 5
postgres=#SELECT ARRAY[1,2,3] || ARRAY[[4,5,6],[7,8,9]] AS RESULT; result --------------------------- {{1,2,3},{4,5,6},{7,8,9}} (1 row)
- Description: Concatenates elements with an array.
1 2 3 4 5
postgres=#SELECT 3 || ARRAY[4,5,6] AS RESULT; result ----------- {3,4,5,6} (1 row)
- Description: Concatenates arrays with elements.
1 2 3 4 5
postgres=#SELECT ARRAY[4,5,6] || 7 AS RESULT; result ----------- {4,5,6,7} (1 row)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot