|
|
|
|
|
by garethrees
3673 days ago
|
|
It makes sense to store serialized data structures in the database when these conditions apply: 1. There are no use cases that would require you to SELECT on the fields in the serialized data structures. 2. You anticipate that the data structures are going to change frequently during development, so that turning them into relations is going to involve a lot of schema migrations. Basically you give up the possibility of being able to SELECT on some of the data in return for being able to change its format rapidly and cheaply. I worked on a project recently where this was helpful -- when I designed the database schema I didn't know the details of many of the data structures that were going to have to be stored there. From the use cases I could deduce the set of fields that would need to be SELECTed on, but the other fields were ill-defined. By storing them as blobs (actually as JSONB fields, since this was PostgreSQL) I could safely defer the decision about how to design these parts of the database, without incurring lots of schema migrations along the way. |
|
Experience has taught me that it's next to impossible to know what types of queries will be needed for the entire lifetime of a project. If you absolutely must store data like this, please leave a clear migration path for moving some or all of it into well structured tables when (not if) it becomes necessary.