4 ms·
I didn't see this mentioned in the article but with JSONB you can leverage operators to know what data changed. > -- record = {"id": 1, "name": "bar"}, old_r
by scwoodal 5y ago
I didn't see this mentioned in the article but with JSONB you can leverage operators to know what data changed.
> -- record = {"id": 1, "name": "bar"}, old_record = {"id": 1, "name": "foo"}
> select record - old_record where id=3;
name => bar
>
- netcraft 5y agoI dont think this is built in, I think you must have an extension or custom operator providing that: https://dbfiddle.uk/?rdbms=postgres_14&fiddle=273a440d043a82668825ba2dead68b99 https://dbfiddle.uk/?rdbms=postgres_14&fiddle=273a440d043a82...
- scwoodal 5y agoAh yes, I was thinking HSTORE. https://dbfiddle.uk/?rdbms=postgres_14&fiddle=2f406630f367b52a8f4868bdac0cc931 https://dbfiddle.uk/?rdbms=postgres_14&fiddle=2f406630f367b5...
- efxhoy 5y agoThis SO answer has a good jsonb diff function: https://stackoverflow.com/a/36043269 https://stackoverflow.com/a/36043269