0

is it a good practice to hold objects with strings the size of 200 chars and more in my SQL db? if not, what should be my limit? It's important for me because in my case I could have a lot of these entities, perhaps over few millions.

my hunch says I should keep the objects data in db and hold just the string fields in outer files. the reasons I think about are mostly for better cache management and to keep the DB file slim. but I couldn't find any information to confirm or contradict my assumption and I don't want to overkill it.

thanks!

Ronen Ness
  • 9,923
  • 4
  • 33
  • 50

2 Answers2

2

For a field of varying length, you can use a TextField instead of a CharField so you don't have to set a size.

Both varying length fields and TextFields are generally intended for large amounts of text.

dhana
  • 6,487
  • 4
  • 40
  • 63
  • well it wasn't what I was asking, but your answer did lead me to this http://stackoverflow.com/questions/7354588/django-charfield-vs-textfield, and to read about char vs varchar, which gave me some useful information. but I'm still not sure if it's a good practice to hold many potentially long string fields in the DB? thanks – Ronen Ness May 14 '14 at 10:01
1

In general it doesn't matter for PostgreSQL.

text and varchar are the same thing internally, it's just that varchar has an optional length constraint.

Both are of indefinite length, both are compressable, both may be stored out-of-line.

There's rarely a reason to actively restrict field sizes.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778