3 ms·
I wish PostgreSQL would support better syntax for JSON updates. You can use `->>` to navigate the JSON fields, but there's nothing similar for updates. You have
by cyberax 2y ago
I wish PostgreSQL would support better syntax for JSON updates. You can use `->>` to navigate the JSON fields, but there's nothing similar for updates. You have to use clumsy functions or tricks with `||` and string casting.
- joaohaas 2y agoIdk, `jsonb_set` and `||` works good enough for most use cases. For reference, you can use `jsonb_set` to do stuff like: jsonb_set('{"a": [{"b": 1}]}', '{a,0,c}', '2') I think a `||` that works with JSON patches would be nice, but you can easily implement that as an extension if you need it.
- cyberax 2y agoIt's super not great. Instead of having something like: "update blah set field->abc = '123'" you end up with "update blah set field = jsonb_set(field, 'abc', '123');". Not the end of the world, but I have to look up the syntax every time I need to write a query.