Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What data type can I use for very large text fields that is database agnostic?

In my Rails app, I want to store the geographical bounds of places column fields in a database. E.g., the boundary of New York is represented as a polygon: an array of arrays.

I have declared my model to serialize the polygons, but I am unsure whether I should even store them like this. The size of these serialized polygons easily exceed 100,000 characters, and MySQL only can store about 65000 characters in a standard TEXT field.

Now I know MySQL also has a LONGTEXT field. But I really want my app to be database-agnostic. How does Rails handle this by itself? Will it switch automatically to LONGTEXT fields? What about when I start using PostgreSQL?

like image 567
Maarten Avatar asked Feb 06 '13 16:02

Maarten


1 Answers

At this point I suggest you ask yourself - does this data need to be stored, or should be store in a database in this format?

I propose 2 possible solutions:

  1. Store your polygons in the filesystem, and reference them from the database. Such large data items are of little use in a database - it's practically pointless to query against them as text. The filesystem is good at storing files - use it.

  2. If you do need these polygons in the database, store them as normalised data. Have a table called polygon, and another called point, deserialize the polygons and store it in a way that reflects the way that databases are intended to be used.

Hope this is of help.

like image 70
thomasfedb Avatar answered Oct 12 '22 13:10

thomasfedb