Hacker News new | ask | show | jobs
by krastanov 4058 days ago
Naive question from a person with little DB experience: Why store the metadata in JSON inside the database instead of in multiple columns in the same table? Is this not the point of using a database?
3 comments

It's a form of 'document storage' that allows a application to store data without the need to account for everything in the database schema.
It depends on what those columns are. For this case multiple columns are probably better, but if you're trying to search over multiple document types a JSON column could be more flexible.
If I'm not mistaken: Altering a table can be costly and may cause a performance issues, specially if you have millions of records. Rows will be most likely locked and get updated and during this process other threads should wait until related row become "free".
That only happens if you add a non-nullable column.