Logical Operators
Compared with the original openGauss, Dolphin has two new logical operators:
- The && operator is added.
- The || operator is added.
&&
Description: When b_compatibility_mode is set to TRUE, it indicates the logical AND operation. The supported types include Boolean, time, date, integer, floating point, and bit string. The truth table is as follows:
a b Result of a && b TRUE TRUE TRUE TRUE FALSE FALSE TRUE NULL NULL FLASE FALSE FALSE FALSE NULL FALSE NULL NULL NULL The following table describes the processing of different input types.
Data Type Processing Method Boolean The logical AND operation is performed according to the truth table. Integer Only the zero value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical AND operation is performed. Floating point Only zero is converted to Boolean false, and other values are converted to Boolean true. Then, the logical AND operation is performed. Bit string Only the all-0 value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical AND operation is performed. Time The conversion mode of the time type depends only on the hour part. When '00:xx:xx' is entered, the time type is converted to Boolean false. When 'yy:xx:xx' is entered, if **yy** is not 0, the time type is converted to Boolean true. Then, the logical AND operation is performed. Date The conversion mode of the date type depends only on the year part. When '0000-xx-xx' is entered, the date type is converted to Boolean false. When 'yyyy-xx-xx' is entered, if **yy** is not 0, the date type is converted to Boolean true. Then, the logical AND operation is performed. Return type: Boolean
Example:
openGauss=# SELECT 1 && 1; ?column? ---------- t (1 row)
||
Description: When sql_mode is not set to 'pipes_as_concat', it indicates a logical OR operation. The supported types include Boolean, time, date, integer, floating point, and bit string. The truth table is as follows:
a b Result of a || b TRUE TRUE TRUE TRUE FALSE TRUE TRUE NULL TRUE FLASE FALSE FALSE FALSE NULL NULL NULL NULL NULL The following table describes the processing of different input types.
Data Type Processing Method Boolean The logical OR operation is performed according to the truth table. Integer Only the zero value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical OR operation is performed. Floating point Only the zero value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical OR operation is performed. Bit string Only the all-0 value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical OR operation is performed. Time The conversion mode of the time type depends only on the hour part. When '00:xx:xx' is entered, the time type is converted to Boolean false. When 'yy:xx:xx' is entered, if **yy** is not 0, the time type is converted to Boolean true. Then, the logical OR operation is performed. Date The conversion mode of the date type depends only on the year part. When '0000-xx-xx' is entered, the date type is converted to Boolean false. When 'yyyy-xx-xx' is entered, if **yy** is not 0, the date type is converted to Boolean true. Then, the logical OR operation is performed. Return type: Boolean
Example:
openGauss=# SELECT 0 || 0; ?column? ---------- f (1 row)
Feedback