6 ms·
1. Postgres has a json and jsonb datatype specifically to be your values. 2. It has built in query and modification tools that can manage the nested objects an
by kazagistar 9y ago
1. Postgres has a json and jsonb datatype specifically to be your values.
2. It has built in query and modification tools that can manage the nested objects and array and whatnot.
3. It let's you build indexes to help with all this, including reverse indexes for asking something like "is this string in the array inside this object".
4. You don't have to specify your schema in sone horrid way, you can just throw what you want at it and specify later, and get performance numbers that are competitive and even exceed some popular NoSql stores.
5. You can mix and match freely with all the niceties of a proper SQL database with transactions, joins, constraints, etc, as you see fit to evolve.
So yeah, don't just throw your keys and values into some text table somewhere; but use instead one of the best proper kv stores, that just happens to also be one of the best sql databases, and figure out how you want your schema you need it.
- Mikushi 9y agoSame can be said of MySQL. Not comparing to Postgres, but I've been amazed at how many people do not know that either of these as a powerful JSON type.
- ivanhoe 9y agoYes, too many devs I know haven't even heard about generated columns and virtual indexes in mysql.
- ojosilva 9y agoPostgres JSON(B) falls nearly in the same category. Do not use Postgres as a key value store, use a KV store for that. Postgres JSON is great for storing the original JSON data coming from external APIs and Webhooks, such as Stripe payments. But it's not a silver bullet and really not a first class citizen. SQL query syntax for JSON data is awful, non-standard and requires casting types, which defeats the purpose of schemaless. I believe Postgres JSON types solve a different use case: an app based on a relational schema that needs to store JSON structures eventually. I don't recommend starting off your app basing it on Postgres JSON. Use the full relational Postgres instead and do it right from the start.