MySql - 不支持BLOB / TEXT列

时间:2017-04-27 07:49:03

标签: mysql stored-procedures temp-tables

create temporary table if not exists tmp engine=memory 
SELECT id, CONCAT(TRIM(lastName),TRIM(firstName),TRIM(zip)) AS identify
FROM customers 
GROUP BY identify;

在运行该过程时,我收到以下错误消息:

The used table type doesn't support BLOB/TEXT columns

我已经看过this帖子,但它并没有帮助我。

列上的类型如下:

lastName -> VARCHAR(255)
firstName -> VARCHAR(255)
zip -> VARCHAR(10)

当我从程序中排除zip时,它的工作原理应该如此,我猜varchar的长度有问题吗?

有没有人知道解决方案而不将zip的varchar长度从10改为255?

2 个答案:

答案 0 :(得分:1)

发生率由常数CONVERT_IF_BIGGER_TO_BLOB

的值表示
/**
  CHAR and VARCHAR fields longer than this number of characters are converted
  to BLOB.
  Non-character fields longer than this number of bytes are converted to BLOB.
  Comparisons should be '>' or '<='.
*/
#define CONVERT_IF_BIGGER_TO_BLOB 512   /* Used for CREATE ... SELECT */

mysql-server/sql/sql_const.h::52

  

16.3 The MEMORY Storage Engine

     
      
  • ...

  •   
  • 支持MEMORY不支持的可变长度数据类型(包括BLOB和TEXT)。

  •   

示例:

mysql> DROP TEMPORARY TABLE IF EXISTS `tmp`;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TEMPORARY TABLE IF NOT EXISTS `tmp` ENGINE=MEMORY
    -> SELECT SPACE(512) `tmp_col`;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> DROP TEMPORARY TABLE IF EXISTS `tmp`;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TEMPORARY TABLE IF NOT EXISTS `tmp` ENGINE=MEMORY
    -> SELECT SPACE(513) `tmp_col`;
ERROR 1163 (42000): The used table type doesn't support BLOB/TEXT columns

尝试:

mysql> DROP TABLE IF EXISTS `tmp`, `customers`;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE IF NOT EXISTS `customers` (
    ->   `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    ->   `lastName` VARCHAR(255) NOT NULL,
    ->   `firstName` VARCHAR(255) NOT NULL,
    ->   `zip` VARCHAR(10) NOT NULL
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TEMPORARY TABLE IF NOT EXISTS `tmp` (
    ->   `id` BIGINT UNSIGNED NOT NULL PRIMARY KEY,
    ->   `identify` VARCHAR(520) NOT NULL
    -> ) ENGINE=MEMORY;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO `tmp`
    -> SELECT `id`, CONCAT(TRIM(`lastName`),
    ->                     TRIM(`firstName`),
    ->                     TRIM(`zip`)) `identify`
    -> FROM `customers`
    -> GROUP BY `id`, `identify`;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

答案 1 :(得分:1)

我对ENGINE = MEMORY的经验是,charset也是相关的。 varchar(65000)与charset latin1工作; charset UTF8没有 ENGINE = MEMORY DEFAULT CHARSET = latin1