Integer Array Operation Using Operators - part 2
Contains:
Assume A is an integer array and B is an integer array, We can check, whether the Array A contains Array B by the operator @> and Array A contained in Array B by the operator <@. And it produces a BOOLEAN value as TRUE or FALSE.
Example:
SELECT ARRAY[1,2,3]::INT[] @> ARRAY[2]::INT[] AS a
a
------
true
SELECT ARRAY[2]::INT[] <@ ARRAY[1,2,3]::INT[] as a
Contains:
Assume A is an integer array and B is an integer array, We can check, whether the Array A contains Array B by the operator @> and Array A contained in Array B by the operator <@. And it produces a BOOLEAN value as TRUE or FALSE.
Example:
SELECT ARRAY[1,2,3]::INT[] @> ARRAY[2]::INT[] AS a
a
------
true
SELECT ARRAY[2]::INT[] <@ ARRAY[1,2,3]::INT[] as a
a
------
true
Overlap:
Assume A is an integer array and B is an integer array. We can check,Whether the Array A and Array B have any common values in it by the operator &&. And it produces a BOOLEAN value as TRUE or FALSE.
Example:
SELECT ARRAY[1,2,3]::INT[] && ARRAY[2]::INT[] AS a
a
------
true
SELECT ARRAY[2]::INT[] && ARRAY[1,2,3]::INT[] as a
a
------
true
Concatenation:
We can concatenate two arrays in the Integer array operation in postgreSQL . And it can be done by the operator ||.
Example:
i) SELECT ARRAY[1,2,3]::INT[] || ARRAY[4]::INT[] AS a
a
------------
{1,2,3,4}
SELECT ARRAY[4]::INT[] || ARRAY[1,2,3]::INT[] AS a
a
-----------
{1,2,3,4}
SELECT ARRAY[1,2,3]::int[] || ARRAY[[4,5,6],[7,8,9]] AS a
a
--------------------------------
{{1,2,3},{4,5,6},{7,8,9}}