SQLite Forum

documenting SQLite's "IS" behavior
Login
For implicit promotions one would expect the bool to be promoted to int rather than the int reduced to a bool.

Note that in SQLite the + operator does not change types.  It can even be applied to a string:

```
select +'hi';
hi
```

But anyway, it's not that important.

Other versions of "true" don't work; well, there is no such thing as a boolean type in SQLite so it has kind of no hope.  This kind of stuff isn't going to work:

```
sqlite> select 2 is (0==0);
0
```

Note that the ISO operator commutes, but:

```
sqlite> select true is 2;
0
```

"IS" really is just like the ISO operator except for that special case for boolean literals on the right.  Which is not really a surprise because that's how the code is written.

```
    case TK_IS:
    case TK_ISNOT: {
      Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
      assert( !ExprHasProperty(pExpr, EP_Reduced) );
      /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
      ** and "x IS NOT FALSE". */
      if( ALWAYS(pRight) && (pRight->op==TK_ID || pRight->op==TK_TRUEFALSE) ){
        int rc = resolveExprStep(pWalker, pRight);
        if( rc==WRC_Abort ) return WRC_Abort;
        if( pRight->op==TK_TRUEFALSE ){
          pExpr->op2 = pExpr->op;
          pExpr->op = TK_TRUTH;
          return WRC_Continue;
        }
      }
      /* no break */ deliberate_fall_through
    }
```