Logical Operators
Compared with the original openGauss, Dolphin has two new logical operators:
- The && operator is added.
- The || operator is added.
&&
Description: When
dolphin.b_compatibility_mode
is set toTRUE
, it indicates the logical AND operation. The supported types include Boolean, time, date, integer, floating point, bit string, and character. 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. Character The conversion of the character type depends on whether the header of the character type is a number. If the header of the character type is not a number, the character type is directly converted to Boolean false. If the value is a number, the value 0 is converted to Boolean false. Otherwise, the value is converted to Boolean true, and 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, bit string, and character. 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. Character The conversion of the character type depends on whether the header of the character type is a number. If the header of the character type is not a number, the character type is directly converted to Boolean false. If the value is a number, the value 0 is converted to Boolean false. Otherwise, the value is converted to Boolean true, and then the logical OR operation is performed. Return type: Boolean
Example:
openGauss=# SELECT 0 || 0; ?column? ---------- f (1 row)
Feedback