MySQL中是否有类似PostgreSQL的数组数据类型?

时间:2021-10-31 16:21:07

I need to store arrays of integers in a MySQL database. In there something equivalent to this in MySQL?

我需要在MySQL数据库中存储整数数组。在MySQL中有类似的东西吗?

 CREATE TABLE tictactoe (
    squares   integer[3][3]
);

I want to store matrices with dimension 20x6. I don't feel like creating a table with 120 columns. There is no need to query on this field, just need to store and retrieve full matrices.

我想存储20x6维的矩阵。我不想创建一个包含120列的表。不需要查询这个字段,只需要存储和检索完整的矩阵。

If it matters, i use Perl.

如果重要的话,我使用Perl。

3 个解决方案

#1


15  

No, there is no such thing. There is an open worklog for that, but no progress has been made on implementing this feature.

不,没有这种事。对此有一个开放的工作日志,但是在实现这个特性方面没有取得任何进展。

You have to emulate this somehow, using either multiple fields (9 in your case) or pack the integers together into a larger datatype (blob for example).

您必须以某种方式模拟这一点,使用多个字段(在您的例子中为9)或将整数打包为一个更大的数据类型(例如blob)。

#2


4  

Store them in a text format using proper delimiters. ex:- If you want to store numbers from 1 to 9, store them in text format as 1-2-3-4-5-6-7-8-9 where '-' is a delimiter. Explode the string and get the desired numbers.

使用适当的分隔符以文本格式存储它们。例句:-如果你想把数字从1存储到9,用文本格式将它们存储为1-2-3-4-5-6-7-8-9,其中'-'是分隔符。爆炸字符串,得到所需的数字。

#3


1  

No there is not. Short answer but without knowing what you have do that is the answer.

没有没有。简短的回答,但不知道你做了什么,那就是答案。

#1


15  

No, there is no such thing. There is an open worklog for that, but no progress has been made on implementing this feature.

不,没有这种事。对此有一个开放的工作日志,但是在实现这个特性方面没有取得任何进展。

You have to emulate this somehow, using either multiple fields (9 in your case) or pack the integers together into a larger datatype (blob for example).

您必须以某种方式模拟这一点,使用多个字段(在您的例子中为9)或将整数打包为一个更大的数据类型(例如blob)。

#2


4  

Store them in a text format using proper delimiters. ex:- If you want to store numbers from 1 to 9, store them in text format as 1-2-3-4-5-6-7-8-9 where '-' is a delimiter. Explode the string and get the desired numbers.

使用适当的分隔符以文本格式存储它们。例句:-如果你想把数字从1存储到9,用文本格式将它们存储为1-2-3-4-5-6-7-8-9,其中'-'是分隔符。爆炸字符串,得到所需的数字。

#3


1  

No there is not. Short answer but without knowing what you have do that is the answer.

没有没有。简短的回答,但不知道你做了什么,那就是答案。