mysql - 创建表时分区语法错误: MySQL

标签 mysql sql partitioning create-table

我在创建带有分区的 MySQL 表时出错。

    CREATE TABLE employees (
    context VARCHAR(25),
    id INT
)
PARTITION BY LIST(context) (
    PARTITION pNorth VALUES IN('ads','asd')
);

它给出:

ERROR 1064 (42000): VALUES value must be of same type as partition function near ''asd') )' at line 6

请帮帮我。

最佳答案

我认为这里的问题是您正在尝试对 VARCHAR 数据类型列进行分区。对于 LIST 分区,您必须引用 INTEGER 类型列。来自 the docs :

List partitioning in MySQL is similar to range partitioning in many ways. As in partitioning by RANGE, each partition must be explicitly defined. The chief difference between the two types of partitioning is that, in list partitioning, each partition is defined and selected based on the membership of a column value in one of a set of value lists, rather than in one of a set of contiguous ranges of values. This is done by using PARTITION BY LIST(expr) where expr is a column value or an expression based on a column value and returning an integer value, and then defining each partition by means of a VALUES IN (value_list), where value_list is a comma-separated list of integers.

不过肯定是误导性错误!

编辑

您应该注意的是通过 LIST COLUMNS 进行分区,而不是通过 LIST 进行分区。因此:

CREATE TABLE employees (
    context VARCHAR(25),
    id INT
)
PARTITION BY LIST COLUMNS(context) (
    PARTITION pNorth VALUES IN('ads','asd')
);

关于mysql - 创建表时分区语法错误: MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21599056/

相关文章:

python - 在 Win7 和 Python 2.7 上安装 mysql-python 模块时出错

php - sql语句查询计数数据

java - PostgreSQL + Java

apache-spark - Spark SQL 如何读取 Parquet 分区文件

hadoop - 自定义分区程序示例

php - AJAX 调用不适用于 PHP

php - 如何在mysql中散列自动增量

PHP SQL SELECT 查询适用于除一个表之外的每个表

SQL - 选择表中与其他行具有相似特征的行

java - 网络、集群和虚拟分区