Standard SQL boolean operator IS vs. equals (=) operator

前端 未结 2 1348
无人共我
无人共我 2020-12-09 16:41

On the Wikipedia page for SQL there are some truth tables about boolean logic in SQL. [1] The Wikipedia page seems to source the SQL:2003 standard.

The truth table f

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 17:03

    That's a new one for me.

    If I read that correctly the grammar defines three predicates solely for use with the boolean datatype IS TRUE, IS FALSE, IS UNKNOWN.

    These differ from their equality counterparts in that they only evaluate to True or False. Never to Unknown. i.e. UNKNOWN = TRUE would evaluate to UNKNOWN but UNKNOWN IS TRUE evaluates to False.

    The full truth tables for IS and = are below.

    +---------+-------+-------+---------+
    |   IS    | TRUE  | FALSE | UNKNOWN |
    +---------+-------+-------+---------+
    | TRUE    | TRUE  | FALSE | FALSE   |
    | FALSE   | FALSE | TRUE  | FALSE   |
    | UNKNOWN | FALSE | FALSE | TRUE    |
    +---------+-------+-------+---------+
    

    As opposed to

    +---------+---------+---------+---------+
    |    =    |  TRUE   |  FALSE  | UNKNOWN |
    +---------+---------+---------+---------+
    | TRUE    | TRUE    | FALSE   | UNKNOWN |
    | FALSE   | FALSE   | TRUE    | UNKNOWN |
    | UNKNOWN | UNKNOWN | UNKNOWN | UNKNOWN |
    +---------+---------+---------+---------+
    

提交回复
热议问题