tidb icon indicating copy to clipboard operation
tidb copied to clipboard

Binary literal not having the BINARY flag

Open breezewish opened this issue 9 years ago • 2 comments

MySQL:

mysql> SELECT _binary'string';
Field   1:  `string`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  binary (63)
Length:     6
Max_length: 6
Decimals:   31
Flags:      NOT_NULL BINARY 


+--------+
| string |
+--------+
| string |
+--------+
1 row in set (0.00 sec)

TiDB:

mysql> SELECT _binary'string';
Field   1:  `string`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8_general_ci (33)
Length:     6
Max_length: 6
Decimals:   31
Flags:      


+--------+
| string |
+--------+
| string |
+--------+
1 row in set (0.00 sec)

breezewish avatar Aug 17 '17 03:08 breezewish

Nice catch, both Collation and Flags are different.

ngaut avatar Aug 17 '17 03:08 ngaut

it seems like a same issue below

in case 1 it works as expected

MySQL [(none)]> SELECT LOWER(BINARY 'String');
Field   1:  `LOWER(BINARY 'String')`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  binary (63)
Length:     0
Max_length: 6
Decimals:   31
Flags:      BINARY 


+------------------------+
| LOWER(BINARY 'String') |
+------------------------+
| String                 |
+------------------------+
1 row in set (0.00 sec)

in case 2 the user variable doesn't work correctly

MySQL [(none)]> SET @str = BINARY 'String';
Query OK, 0 rows affected (0.01 sec)

MySQL [(none)]> SELECT LOWER(@str);
Field   1:  `LOWER(@str)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8_general_ci (33)
Length:     0
Max_length: 6
Decimals:   31
Flags:      


+-------------+
| LOWER(@str) |
+-------------+
| string      |
+-------------+
1 row in set (0.00 sec)

tshqin avatar Aug 18 '17 13:08 tshqin