gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:41:09 25 4
gpt4 key购买 nike

我在创建带分区的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com