DEV Community

Qing
Qing

Posted on

Operators

An operator in openGauss is a reserved keyword or character, and it is generally used in the WHERE statement as a filter condition. Common operators are as follows:

Arithmetic Operators

Image description

Image description

· *

Description: Multiplication

Example:

Image description

· /

Description: Division (The result is not rounded.)

Example:

Image description

Image description

· +/-

Description: Positive/Negative

Example:

Image description

· %

Description: Model (to obtain the remainder)

Example:

Image description

· @

Description: Absolute value

Example:

Image description

· ^

Description: Power (exponent calculation)

Example:

Image description

· |/

Description: Square root

Example:

Image description

· ||/

Description: Cubic root

Example:

Image description

· !

Description: Factorial

Example:

Image description

· !!

Description: Factorial (prefix operator)

Example:

Image description

· &

Description: Binary AND

Example:

Image description

· |

Description: Binary OR

Example:

Image description

· #

Description: Binary XOR

Example:

Image description

· ~

Description: Binary NOT

Example:

Image description

· <<

Description: Binary shift left

Example:

Image description

· >>

Description: Binary shift right

Example:

Image description

Comparison Operators

Comparison operators are available for the most data types and return Boolean values.

All comparison operators are binary operators. Only data types that are the same or that can be implicitly converted can be compared by using comparison operators.

Table 1 describes the comparison operators provided by openGauss.

Table 1 Comparison operators

Image description

Comparison operators are available for all relevant data types. All comparison operators are binary operators that returned values of Boolean type. The calculation priority of the inequality sign is higher than that of the equality sign. If the entered data is different and cannot be implicitly converted, the comparison fails. For example, an expression such as 1<2<3 is invalid because the less-than sign (<) cannot be used to compare Boolean values and 3.

Example:

Image description

Logical Operators

Common logical operators include AND, OR, and NOT. The operation result can be TRUE, FALSE, or NULL (which means unknown). Their priorities are NOT > AND > OR.

The operators AND and OR are commutative. That is, you can switch the left and right operand without affecting the result.

Table 2 lists the calculation rules, where a and b represent logical expressions.

Table 2 Operation rules

Image description

Top comments (0)