I've recently stumbled into an interesting Mysql query:

SELECT ~0; results: 18446744073709551615

Which is the max value of a bigint unsigned. What does the tilde operator do in this case?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top