[8.x] Add better bitwise operators support #41072
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Impetus
This addresses the problem mentioned in issue #40484, while avoiding pitfalls brought up by issue #40757.
This PR was originally submitted as #40529, by reverted by #40791.
Changes
The problem with previous implementation was assuming that bitwise operators always produce an integer (or at least a number).
I failed to see that these operators (notably
>>
and<<
) where not only bitwise arithmetic operators for PostgreSQL but also range operators (as described here).In the issue #40757, we fall exactly in this case.
Thus, the approach I took this time was to force a cast to bool in PostgreSQL, which solves both the initial problem and ones caused by the previous implementation.
Since both MySQL and SQLite support "implicit casting" to boolean, it is essentially a noop for those grammars.
SQL Server still requires the "old trick" of
!= 0
. The documentation states that it "converts the result to an integer.", so the comparison is safe.