3 ms·
I use JSONB heavily for a few things: * Tags. Basically the same as array of strings, which postgres also supports, but I don't need to remember a different se
by stickfigure 7y ago
I use JSONB heavily for a few things:
* Tags. Basically the same as array of strings, which postgres also supports, but I don't need to remember a different set of operators.
* Polymorphic data. Instead of countless nullable fields that represent the union of all fields of all subtypes, I just include a single (or in some cases, a couple) JSONB columns whose schema varies by type. The schema is enforced by types at the application layer.
* Truly schemaless data. Sometimes I just need to keep track of an arbitrary JSON blob defined by some other service (say, an Order from shopify). Just dump it in my table as-is and now I can search orders.
Postgres' json functions and operators aren't wholly intuitive (updating bits of nested data can be hard; it's really a lot better if you can just update whole json fields at once) but overall it works pretty well.
- kumarvvr 7y ago> Polymorphic data. Instead of countless nullable fields that represent the union of all fields of all subtypes, I just include a single (or in some cases, a couple) JSONB columns whose schema varies by type. The schema is enforced by types at the application layer. I am surprised there aren't many database interface libraries that build upon this. This is a very powerful aspect of JSONB in PGSQL.