-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support SQL IS
binary operator
#358
Comments
Is |
looking this up, is can only be used for trivalued booleans (true, false, null) |
So the proper type here is more like |
Should be |
Yes, good catch- thanks! |
I hadn't realized that the use is limited to true/false/null. The signature looks good to me 👍 |
Yeah, it's limited to -- Boolean operator
is :: SqlExpr (Value (Maybe Bool)) -> SqlExpr (Value (Maybe Bool)) -> SqlExpr (Value Bool)
-- Synonym for `isNothing`
isNull :: SqlExpr (Value (Maybe a)) -> SqlExpr (Value Bool)
-- Synonym for `not_ . isNothing`
isNotNull :: SqlExpr (Value (Maybe a)) -> SqlExpr (Value Bool) |
I found myself manually creating the following definition:
Equivalently, one can imagine the following operator:
(although this one can be done with the
not_ (is ...)
function)The
IS
binary operator is most commonly seen inIS NULL
andIS NOT NULL
. esqueleto indeed has this in theisNothing
function, but they can also be used for other values, e.g.foo IS true
. The reason to useIS
over=
here is because they have different behaviors regarding NULL.Here are the truth tables for
x = y
andx IS y
for booleans:x = y
true
false
NULL
true
true
false
NULL
false
false
true
NULL
NULL
NULL
NULL
NULL
x IS y
true
false
NULL
true
true
false
false
false
false
true
false
NULL
false
false
true
I didn't make a pull request because this function might be up to debate. Arguably, one might say that with a correct Persistent table definition, you statically know whether a column is NULL or not, so the
IS
operator may not technically be needed. On the other hand, there might be other expressions whereNULL
sneaks in to give funny behavior. What do you think?Also, apologies if this issue is duplicate. It's kind of hard to search for a two-letter operator 😅
The text was updated successfully, but these errors were encountered: