MySQL when a = 0, b = 0, but a <> b (binary)
5
votes
2
answers
246
views
Any idea of why this is so,
CREATE TABLE f AS
SELECT b'000000001' AS a, x'01' AS b;
This creates two columns of
a
varbinary(2) NOT NULL,
b
varbinary(1) NOT NULL
However, when I run,
SELECT a=0, b=0, a=b, ab FROM f;
+-----+-----+-----+------+
| a=0 | b=0 | a=b | ab |
+-----+-----+-----+------+
| 1 | 1 | 0 | 1 |
+-----+-----+-----+------+
What's going on here? From the [docs on *The BINARY and VARBINARY Types*,](https://dev.mysql.com/doc/refman/8.0/en/binary-varbinary.html)
> **All bytes are significant in comparisons, including ORDER BY
and DISTINCT
operations.** 0x00
bytes and spaces are different in comparisons, with 0x00 b
, but why does a=0
, or b=0
there?
Asked by Evan Carroll
(65502 rep)
May 2, 2018, 10:42 PM
Last activity: Jun 21, 2019, 02:28 PM
Last activity: Jun 21, 2019, 02:28 PM