Is there any array data type in MySQL like in PostgreSQL?
Solution 1
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).
Solution 2
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.
Solution 3
No there is not. Short answer but without knowing what you have do that is the answer.
Related videos on Youtube
Comments
-
Francisco R almost 4 years
I need to store arrays of integers in a MySQL database. In there something equivalent to this in 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.
If it matters, i use Perl.
-
user2449612 almost 11 yearsyou can serialiaze this array and when you want to get array from this value again, just unserialize it. example in PHP php.net/manual/en/function.serialize.php
-
-
chantheman about 13 yearsUnfortunately you will just need to handle it on your application side. There are some tricks out there but it is best to just adapt your application.
-
Francisco R about 13 yearsThanks! Pack the data into
blob
seems to be a valid workaround for my needs. -
wobbily_col about 9 yearsWould a delimited string not be easier to parse than a blob?