Would there be any drawbacks to using a normal update statement to update a json(b) column like so:
update "events" set "properties" = '{"type":"graph"}'
Instead of using the jsonb_set function provided by PostgreSQL, which would turn into this statement:
update "events" set jsonb_set("properties", {'type'}, 'graph')
When using eg. an ORM, and calling .save() on a Model for which you've just updated a JSON field, the first method will be called, but as there is no mention of this way of doing things in the PostgreSQL documentation, I fear this may have some drawbacks.
Given that I'm not incredibly familiar with anything regarding performance in databases, I thought I'd come and ask a question here.
Thanks in advance!
Best Answer
Update: If the result value of jsonb is the same, then the only difference is
jsonb_set
would take additional CPU (and ms) to run. In both cases you runSET column = VALUE
, but if resulted jsonb value is bifferent,both your statements are very much different, here is example.sample:
jsonb_set
jsonb value changed at specified path! And now with
update .. set
:whole jsonb is overwritten. not just "a" key