|
|
|
|
|
by quietbritishjim
2743 days ago
|
|
For it to replace MongoDB's aggregation pipeline, it would need to play nicely with JSONB. Does it do that? This is the thing I'm really missing. For example, if documents in the JSONB column all look roughly like this: {
"someArrayField": [
{ "key": "steve", "value": 7 },
{ "key": "bob", "value": 15 },
],
"someOtherField": [ "whatever" ]
}
* Can I count the number of entries in someArrayField, summed across all records?* Can I get the per-record mean of the "value" sub-field, summed across all records? * Can I filter by records that have a "someArrayField" entry where "key" is "steve" and "value" is at least 10 (the above record should NOT match)? |
|
The jsonb_array_elements function is roughly similar to Mongo’s $unwind pipeline op. It explodes a JSON array into a set of rows. From there it’s pretty simple aggregates to achieve what you’re looking for.
I was evaluating Mongo a couple months back to solve roughly the same problems. Eventually discovered Postgres already had what I was looking for.