MySql - 不支持 BLOB/TEXT 列

标签 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 的解决方案?

最佳答案

发生率由常量 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

  • ...

  • Support for variable-length data types (including BLOB and TEXT) not supported by MEMORY.

例子:

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

关于MySql - 不支持 BLOB/TEXT 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43651687/

相关文章:

php - 如何使用geoplugin在php中获取国家名称?

mysql - 尝试使用一个固定的 WHERE 语句和另一个可选的语句获取数据

php - 以表格格式php显示来自mysql查询的数据

sql-server - 在存储过程中创建触发器

sql - 通过连接临时表插入多条记录

MySQL - 使用 `if` 的存储过程中的语法错误

mysql - 在存储过程 MYSQL 中创建临时表

php - 数据库表名区分大小写

temp-tables - 如何在 redshift 中创建和调用临时表

mysql - 锁定 View 不可编辑