AnalyticDB for PostgreSQL is compatible with the logical operators of PostgreSQL. This topic describes the logical operators that are supported by AnalyticDB for PostgreSQL and provides examples on how to use the logical operators.
For information about the logical operators of PostgreSQL, see Logical Operators.
Overview
Logical operators are symbols or functions used in programming languages and mathematical logic to combine or manipulate Boolean expressions. You can use logical operators to construct complex conditions. In most cases, Boolean values in programming include TRUE and FALSE. Logical operators mainly include the following operators:
AND (Logical AND)
Symbols: && (in C, C++, and Java) and AND (in Python).
Description: returns TRUE if both expressions are TRUE and FALSE otherwise.
OR (Logical OR)
Symbols: || (in C, C++, and Java) and OR (in Python).
Description: returns TRUE if at least one of the expressions is TRUE and FALSE otherwise.
NOT (Logical NOT)
Symbols: ! (in C-like languages) and NOT (in Python).
Description: inverts the Boolean value of an expression.
Truth tables
A truth table of logical expressions shows all possible input combinations and the corresponding output results. Binary logical operators are operators that operate on two logical values, such as AND and OR. Unary logical operators are operators that operate on only one logical value, such as NOT. The following tables show the truth tables of the AND, OR, and NOT logical operators.
a | b | a AND b | a OR b |
TRUE | TRUE | TRUE | TRUE |
TRUE | FALSE | FALSE | TRUE |
TRUE | NULL | NULL | TRUE |
FALSE | FALSE | FALSE | FALSE |
FALSE | NULL | FALSE | NULL |
NULL | NULL | NULL | NULL |
a | NOT a |
TRUE | FALSE |
FALSE | TRUE |
NULL | NULL |