In PostgreSQL, we can use the || operator to concatenate two arrays. We can also use it to append or prepend a (compatible) non-array value to an array.
operators
Using the <@ Operator in PostgreSQL
In PostgreSQL, the <@ operator checks to see whether the second array contains the first array. That is, whether or not the array on the right of the operator contains all elements in the array to the left.
The function returns a Boolean result: It returns true if the second array contains the first array, and false if it doesn’t. If the result is unknown, it returns NULL.
How the @> Operator Works in PostgreSQL
In PostgreSQL, the @> operator checks to see whether the first array contains the second array. That is, whether or not the array on the left of the operator contains all elements in the array to the right.
The function returns a Boolean result: It returns true if the first array contains the second, and false if it doesn’t. If the result is unknown, it returns NULL.
A Quick Look at the && Operator in PostgreSQL
We can use the && operator in PostgreSQL to check two arrays for any overlapping elements.
We include an array on each side of the operator to compare them, and the result is a Boolean value that indicates whether or not there’s any overlap. A result of True (or t) indicates that there’s an overlap, while False (or f) indicates there’s no overlap.
Overview of the ALL() Construct in PostgreSQL
PostgreSQL has an ALL() construct that we can use when searching for data inside arrays. It returns a Boolean result, which reflects whether the condition is true or not.
Using the ANY() Construct in PostgreSQL
In PostgreSQL, we can use the ANY() construct to perform searches against arrays. It returns a Boolean result, and so we can incorporate this into our searches to return just those rows that yield true or false, as the case may be.
There’s also a SOME() construct, which is a synonym for ANY().
Understanding the Right Shift and Left Shift Operators in SQL Server
SQL Server 2022 introduced a bunch of new bit manipulation functions and operators. Amongst these are the right shift and left shift operators.
The right shift and left shift operators can be used to shift bits to the left or right. Given an integer or binary expression, these operators can shift bits by the amount that we specify.
SQL EXISTS Explained
The SQL EXISTS predicate is used to specify a test for a non-empty set. It returns TRUE or FALSE, depending on the outcome of the test.
When we incorporate the EXISTS predicate operator into our SQL queries, we specify a subquery to test for the existence of rows. If there are any rows, then the subquery is TRUE. If there are no rows, then the subquery is FALSE.
An Introduction to the IS [NOT] DISTINCT FROM Predicate in SQL Server
SQL Server 2022 introduced the IS [NOT] DISTINCT FROM predicate that compares the equality of two expressions and guarantees a true or false result, even if one or both operands are NULL.
Normally if we compare two NULL values, they will always be different (although this will depend on your ANSI_NULLS setting – setting ANSI_NULLS to OFF will result in NULLs being treated as equal). The IS [NOT] DISTINCT FROM predicate enables us to compare NULLs as though they’re equal, even when our ANSI_NULLS setting is set to ON.
3 Reasons GENERATE_SERIES() Returns an Empty Result Set in SQL Server
If you’re using SQL Server’s GENERATE_SERIES() function/relational operator and you’re getting an empty result set, then it could be due to one of the following reasons.