Logical Operators

Compared with the original openGauss, Dolphin has two new logical operators:

  1. The && operator is added.
  2. 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:

    abResult of a && b
    TRUETRUETRUE
    TRUEFALSEFALSE
    TRUENULLNULL
    FLASEFALSEFALSE
    FALSENULLFALSE
    NULLNULLNULL

    The following table describes the processing of different input types.

    Data TypeProcessing Method
    BooleanThe logical AND operation is performed according to the truth table.
    IntegerOnly the zero value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical AND operation is performed.
    Floating pointOnly zero is converted to Boolean false, and other values are converted to Boolean true. Then, the logical AND operation is performed.
    Bit stringOnly the all-0 value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical AND operation is performed.
    TimeThe 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.
    DateThe 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:

    abResult of a || b
    TRUETRUETRUE
    TRUEFALSETRUE
    TRUENULLTRUE
    FLASEFALSEFALSE
    FALSENULLNULL
    NULLNULLNULL

    The following table describes the processing of different input types.

    Data TypeProcessing Method
    BooleanThe logical OR operation is performed according to the truth table.
    IntegerOnly the zero value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical OR operation is performed.
    Floating pointOnly the zero value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical OR operation is performed.
    Bit stringOnly the all-0 value is converted to Boolean false, and other values are converted to Boolean true. Then, the logical OR operation is performed.
    TimeThe 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.
    DateThe 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
编组 3备份
    openGauss 2024-05-19 00:42:09
    cancel