MySQL 中有没有像 PostgreSQL 那样的数组数据类型?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5541175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 22:56:37  来源:igfitidea点击:

Is there any array data type in MySQL like in PostgreSQL?

mysqlpostgresql

提问by Francisco R

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。

采纳答案by theomega

No, there is no such thing. There is an open worklogfor 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)。

回答by Chethan N

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,其中“-”是分隔符。分解字符串并获得所需的数字。

回答by chantheman

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

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