Home > other >  Can it make sense to use the json type for regular, structured data?
Can it make sense to use the json type for regular, structured data?

Time:12-19

I've read this article about JSONB & JSON datatypes. this article is talking about the differences between them and explains their use cases and which is awesome. But, I'm still wondering about the use cases of JSON & JSONB (unstructured data in Postgres) in general.

I know it's always better to use them when we're dealing with unstructured data (since it's the only choice). I wanted to know if is there any scenario you can handle with both JSONB (unstructured) & creating a new table and doing it with JSONB would be a better choice.

PS: I want to hear an example of a scenario in which IT IS LOGICAL to use unstructured data AND DOING IT WITH IS DOABLE. (out of curiosity coz I've never faced anything like this)

CodePudding user response:

Generally, regular tables with appropriate data types (constraints, etc.) are the best choice for regular, structured data - for all the well-documented reasons. But to indulge you:

If you are working with JSON documents in your client, storage size is no problem, you don't need to enforce valid input, referential integrity, or other rules, and the database is just for storage and retrieval (no analytics or data manipulation), then the data type json may be the best choice. Not even jsonb. No transformation back and forth, no complication, no additional sources of error.

I still think the question is not very useful because it's not targeted enough. There will always be some use case where even a sledgehammer makes sense while a needle could do the job. It's just unlikely.

Related:

  • Related