Some SQL dialects such as BigQuery have an IS [NOT] TRUE|FALSE
operator. What is the point of this? For example, can't one just do val=TRUE
or val!=TRUE
? What advantage does the above operator give us, if it only accepts a boolean input?
I can see its usefulness for something like Databricks where it allows things like '1'
or 1
or 'y'
but the above doesn't seem very useful. I suppose one thing it does is give an expected result for NULL
? For example:
select
true is true,
false is true,
null is true
# true | false | false
For once completeness. You have all three predicates:
x is true
: to check if the value of predicate x is true.x is false
: to check if the value of predicate x is false.x is unknown
: to check if the value of predicate x is unknown.Beyond this, in rare cases it may be necessary to distinguish between "predicate x is true" compared to "predicate x is not false". This typically happens for filtering predicates (e.g. the WHERE clause) that use the first form, while constraint validations use the second form.
If you wanted to implement some non-trivial behavior x is true
can come in handy for constraints.