Topic: Arrays to database

Is it possible to save an array of integers to a single column within a database?

I have an array of coordinates that I need saved for future visits.

Thanks in advance!

Re: Arrays to database

To a single column or a single record?

Cause you can always do this to put them each in a different record under the same column:

arr = [1,2,3,4]
arr.each {|num| Coordinate.create(:num => num) }

Re: Arrays to database

As long as the data inside the array doesn't need to be searchable within the database storing it as a raw binary object is better.

If you use danger's method make sure you have some way to associate each record with the right array. Databases are not guaranteed to always be in order.

Something like this:

| id | array_id | value | next_record |

If next_record is null then you are at the end of the array. If there is no record pointing to a row then its the first item in the array.