Skip to content
Advertisement

Can’t see MySQL BIT field value when using SELECT

my_table contains the enabled field which is defined as: enabled BIT NOT NULL DEFAULT 0.

This table has multiple rows with enabled = b'0', and multiple rows with enabled = b'1'.

However, both this:

and this:

show blank in the enabled column:

Why is that? How could I see the value of the enabled field?



Advertisement

Answer

The reason why you can’t see it in terminal is because bit values are non printable characters.

Lets insert following values:

Then select them to file:

First lets view our /tmp/my_table.txtfile as plain text:

“1”,” “
“2”,” “

and then in hex view:

22 31 22 2C 22 01 22 0A 22 32 22 2C 22 00 22 0A

To be able to see those values you can simply CAST them in SELECT:

And that will produce the following output:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement