3 ms·
working with JSONB in Postgres is painful. It's powerful, I love that it's there, but actually using it is always such a chore.
by nonethewiser 2y ago
working with JSONB in Postgres is painful.
It's powerful, I love that it's there, but actually using it is always such a chore.
- krashidov 2y agoGenuinely curious, what do you find painful about it? Is it the syntax? Performance? Or does it just encourage bad practices?
- javaunsafe2019 2y agoI also don't get it - it's super easy to write queries with it. Please elaborate...
- nonethewiser 2y agostuff like this SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @> '{"tags": ["qui"]}'; or SELECT jdoc->'guid', jdoc->'name' FROM api WHERE jdoc @? '$.tags[*] ? (@ == "qui")'; which find documents in which the key "tags" contains array element "qui" https://www.postgresql.org/docs/current/datatype-json.html https://www.postgresql.org/docs/current/datatype-json.html
- Tostino 2y agoI had to ask Claude because I've never worked with Mongo, but apparently the equivalent query for MongoDB is: db.api.find( { "tags": "qui" }, { "guid": 1, "name": 1, "_id": 0 } )
- nonethewiser 2y agoIt's fair to compare alternatives but to be clear I'm not saying postgres JSONB is worse than mongo. I'm not very familiar with mongo either. Im saying it can be tedious is absolute terms. I did not assume this to be universal to document dbs but perhaps it could be. Although your example does seem simpler.