Reputation: 255
how to define integer array as a field when creating new table in mySQL
Upvotes: 1
Views: 4241
Reputation: 39065
You can't. You could do something like convert your array to a comma-separated string, and store this. Or you could define a normalised table structure and have each integer in it's own row. Each row for a given array would also contain some kind of array key as a separate field. This also has the advantage that you can easily query for individual array elements.
Edit In my view the first option is not very elegant. Unless you define your field as TEXT you're going to have issues with varying string lengths, and defining your field as VARCHAR(10000) or whatever is not very efficient. Certainly if your array lengths are long you should consider a normalised solution.
Upvotes: 2
Reputation: 81404
There is currently no way to store an array of integers in MySQL, so you should implement this by yourself. You could choose one of a few things, these two approaches included:
LONGTEXT
: 123|4|65|864
)LONGBLOB
: 0x0000007b000000040000004100000360
)Upvotes: 2