2012年5月3日星期四

ERROR 1170: BLOB/TEXT column 'XX' can't be used in key specification with the used table type

FROM: Better error message for Index on BLOB/TEXT columns

Description:
Consider the following:
[sql]
mysql> create table f2 (a int, b BLOB, KEY(b)) Engine = Falcon;
ERROR 1073 (42000): BLOB column 'b' can't be used in key specification with the used table type
mysql> create table f3 (a int, b TEXT, KEY(b)) Engine = Falcon;
ERROR 1073 (42000): BLOB column 'b' can't be used in key specification with the used table type
[/sql]
The latter message should say TEXT instead of BLOB.

Sveta Smirnova 后面有回复说提示错误的信息已经修改为: BLOB/TEXT column 'b' used in key specification without a key length.

[sql]
mysql> create table f2 (a int, b BLOB, KEY(b)) Engine = Falcon;
ERROR 1170 (42000): BLOB/TEXT column 'b' used in key specification without a key length
mysql> create table f3 (a int, b TEXT, KEY(b)) Engine = Falcon;
ERROR 1170 (42000): BLOB/TEXT column 'b' used in key specification without a key length
[/sql]
上述的测试结果表示确实如 Sveta Smirnov 所言。而且现在不管表使用哪种存储引擎,在为 BLOB/TEXT 类型的字段建立索引时,提示信息由以前的 ERROR 为 1073 的都统一为当前 ERROR 为 1170 的错误信息。

错误处理:
在建立 TEXT/BLOB 类型的字段的索引时,需要为其指定索引的长度。即:
[sql]

mysql> create table f2 (a int, b BLOB, KEY(b (32))) Engine = Falcon;
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> create table f3 (a int, b TEXT, KEY(b (64))) Engine = Falcon;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
[/sql]

没有评论:

发表评论