0

Is there any way to create a column of data type 'array' in mysql table ? like this below :

create table tb_name (
-> column_name INT ARRAY[1000] NOT NULL);
  • 2
    https://stackoverflow.com/questions/17371639/how-to-store-arrays-in-mysql Check this thread, it should help with your question. –  Sep 01 '21 at 15:52

1 Answers1

0

There is no data type to store an array in MySQL. but you can convert your array to JSON and store it in the table and convert it back to an array when you need it.
Also, you can create a multiple tables to store your array of data.

Your main table,

CREATE TABLE tb_name (
`id` INT NOT NULL PRIMARY KEY,
`column_name` VARCHAR(100),
`column_name` VARCHAR(100)
);

Your array data table

CREATE TABLE array_data (
`id` INT NOT NULL PRIMARY KEY,
`pf_tb_table` INT NOT NULL, 
`array_index` INT,
`array_data` VARCHAR(100),
FOREIGN KEY (pf_tb_table) REFERENCES tb_name (id),
);

S.Sachith
  • 536
  • 1
  • 9
  • 21