1

I am trying to understand why you would want to use a JSON column. Is it when you are too lazy to normalize the data at hand?

For example, I have an account's billing information. I could store it as a JSON dump, or break it down into columns, correct?

Which is preferred, and why?

2 Answers 2

2

Generally, normalize it if the structure can be reasonably known in advance.

json / jsonb are good for when you don't control the structure fully, it's highly flexible, it changes over time, etc.

It can sometimes also be handy to store data denormalized for performance, if you always fetch entire "objects", you rarely update them, etc.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there any excuse to be lazy and not normalize, say, a 20-30 column structure if the fields will never need to be queried against except in their whole, combined, object-like state?
1

I would argue that it depends on the situation.

If you have complex hierarchical data, splitting it up into tables can get unwieldy, and retrieving the data might require a large number of joins that can negatively impact performance.

On the other hand, if you need to query for specific values in your data, splitting it up into tables/columns and creating the required indexes will most likely increase query performance.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.