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

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


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.


Postgresql has a library called PostGIS that my company uses to handle geometric locations and calculations that may be very helpful in this situation. I believe postgresql also has two data types that allow arrays and hashes. Arrays are declared, as an example, like text[] where text could be replaced with another data type. Hashes can be defined using the hstore module.


This question answers part of my question: Rails sets a default byte limit of 65535, and you can change it manually.

All in all, whether you will run into trouble after that depends on the database you're using. For MySQL, Rails will automatically switch to the appropriate *TEXT field. MySQL can store up to 1GB of text.

But like benzado and thomasfedb say, it is probably better to store the information in a file so that the database doesn't allocate a lot of memory that might not even be used.