Bug #37559 | Update doesn't work for character set binary and char columns. | ||
---|---|---|---|
Submitted: | 20 Jun 2008 22:29 | Modified: | 11 Jul 2008 9:27 |
Reporter: | Hema Sridharan | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | mysql-6.0-backup | OS: | Linux |
Assigned to: | CPU Architecture: | Any |
[20 Jun 2008 22:29]
Hema Sridharan
[20 Jun 2008 22:37]
Hema Sridharan
Documentation perhaps needs to be more clearer.
[20 Jun 2008 23:40]
Paul DuBois
I think this is not a bug. Examining the structure of the table that is created yields this: -------------- show create table cap -------------- *************************** 1. row *************************** Table: cap Create Table: CREATE TABLE `cap` ( `id` smallint(6) DEFAULT NULL, `country` binary(20) DEFAULT NULL, `city` varbinary(20) DEFAULT NULL, `population` bigint(20) DEFAULT NULL, `capital` binary(20) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=binary 1 row in set (0.00 sec) That is, you have country as a BINARY data type, which is thus zero-padded. So the UPDATE statement compares a zero-padded value with a non-zero-padded value. Changing it as follows yields the desired result: mysql> UPDATE cap SET capital='Delhi' WHERE country=CAST('IND' AS BINARY(20)); Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> select * from cap; +------+----------------------+--------+----------------+----------------------+ | id | country | city | population | capital | +------+----------------------+--------+----------------+----------------------+ | 1 | IND | chn | 87874646468 | Delhi | | 2 | US | Austin | -6466547 | DC | | 3 | Russia | moscow | 76487623235682 | moscow | | 4 | IND | bang | -83875477 | Delhi | +------+----------------------+--------+----------------+----------------------+ 4 rows in set (0.00 sec) Conversion of data types when you specify a character set of binary appears not to be documented. I will add it here: http://dev.mysql.com/doc/refman/5.0/en/string-type-overview.html Zero-padding of BINARY is documented here: http://dev.mysql.com/doc/refman/5.0/en/binary-varbinary.html
[20 Jun 2008 23:46]
Paul DuBois
Description of data type conversion to be added to manual: Specifying the CHARACTER SET binary attribute for a character data type causes the column to be created as the corresponding binary data type: CHAR becomes BINARY, VARCHAR becomes VARBINARY, and TEXT becomes BLOB. For the ENUM and SET data types, this does not occur; they are created as declared. Suppose that you specify a table using this definition: CREATE TABLE t ( c1 VARCHAR(10) CHARACTER SET binary, c2 TEXT CHARACTER SET binary, c3 ENUM('a','b','c') CHARACTER SET binary ); The resulting table has this definition: CREATE TABLE t ( c1 VARBINARY(10), c2 BLOB, c3 ENUM('a','b','c') CHARACTER SET binary );
[10 Jul 2008 23:07]
Hema Sridharan
As sveta mentioned, this bug report can be categorized to documentation team.
[11 Jul 2008 9:27]
Sveta Smirnova
Thank you for the feedback. Reclassified as documentation bug and marked as closed as documentation was updated.