title: Why we should perfer to store the serialized data not the raw code to DB?
body: <p>If we have some code(a data structure) which should be stored in DB, someone always suggests us to store the serialized data not the raw code string.</p>
  
  <p>So I'm not so sure why we should prefer the serialized data.</p>
  
  <p>Give a simple instance(in python):</p>
  
  <p>we've got a field which will store a dict of python, like </p>
  
  <pre><code>{ "name" : "BMW", "category":"car", "cost" : "200000"}
  </code></pre>
  
  <p>so we can serialize it using pickle(a python module) and then store the pickled data to db field.</p>
  
  <p>Or we can store the dict string directly to DB without serializing. </p>
  
  <p>Since we need to convert the string to python data back, two approaches are both easy to do, by using pickle.loads and exec respectively.</p>
  
  <p>So which should be preferred? And why? Is it because exec is much slower than pickle? or some other reasons?</p>
  
  <p>Thanks.</p>