patternsqlMinor
What does SELECT ~0; do?
Viewed 0 times
doesselectwhat
Problem
I've recently stumbled into an interesting Mysql query:
results:
Which is the max value of a bigint unsigned. What does the tilde operator do in this case?
SELECT ~0;results:
18446744073709551615Which is the max value of a bigint unsigned. What does the tilde operator do in this case?
Solution
It selects the logical negation of 0 and returns it in the implicitly converted datatype. Rather than selecting 8 bytes containing all 0's, it selects 8 bytes containing all 1's, returning the maximum possible unsigned value.
Context
StackExchange Database Administrators Q#82476, answer score: 7
Revisions (0)
No revisions yet.