When does it make sense to include WHERE name<>'' AND name IS NOT NULL
It is never required in that context, If Name is NULL
then name<>''
evaluates to UNKNOWN
.
The WHERE
clause only returns rows where the predicate evaluates to true
and rejects rows where it evaluates to false
or unknown
.
Even though it is not required you could maybe make a case for including the redundant predicate for clarity if the code will be maintained by generalist developers that are maybe not too familiar with all the vagaries of the above (though I would rather add a comment for these people then add redundant code).
A circumstance where the expression could make sense would be in a check constraint.
Check constraints reject rows where the expression is false
and accepts ones where it is true
or unknown
So the expression name<>'' AND name IS NOT NULL
would reject NULL
values in this case whereas name<>''
would allow them.
But even in this case it would be best just to declare the column as NOT NULL
.