When can I save JSON or XML data in an SQL Table

前端 未结 8 1726
星月不相逢
星月不相逢 2020-11-27 12:04

When using SQL or MySQL (or any relational DB for that matter) - I understand that saving the data in regular columns is better for indexing sake a

8条回答
  •  心在旅途
    2020-11-27 12:18

    This is too long for a comment.

    If it were "absolutely wrong", then most databases would not support it. Okay, most databases support commas in the FROM clause and I view that as "absolutely wrong". But support for JSON is new development, not a backward-compatible "feature".

    One obvious case is when the JSON struct is simply a BLOB that is passed back to the application. Then there is no debate -- other then the overhead of storing JSON, which is unnecessarily verbose for structured data with common fields in every record.

    Another case is the "sparse" columns case. You have rows with many possible columns, but these vary from row to row.

    Another case is when you want to store "nested" records in a record. JSON is powerful.

    If the JSON has common fields across records that you want to query on, then you are usually better off putting these in proper database columns. However, data is complicated and there is a place for formats such as JSON.

提交回复
热议问题