Updated on 2024-06-03 GMT+08:00

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 can be implicitly converted can be compared using comparison operators.

Table 1 describes comparison operators provided by GaussDB.

Table 1 Comparison operators

Operator

Description

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

=

Equal to

<>, !=, or ^=

Not equal to

  • For comparison operators <=, <>, >=, and ^=, if there is a space between two symbols, it does not affect normal operations. For !=, if there is a space between the exclamation mark (!) and an equal sign (=), the exclamation mark will be identified as factorial, which may cause the result to be inconsistent with the expected result.
  • 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 type 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.
  • Besides, each comparison operator has a corresponding function in the pg_proc system catalog. If the value of the proleakproof attribute of the corresponding function is f, the function is not used to prevent data leakage. If a user only has the permission for a system view, but does not have the permission for the corresponding table, the query plan may not be optimal when the user searches the system view.
  • This operator does not support data of the XML type.