-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get the fields that are updated #196
Comments
No. That sentence was referring to columns that is stored in a TOAST table. |
@eulerto - Makes sense. So, is there a way to get the fields that are actually updated in Postgres? Just wanted to understand the problem area if it's Postgres or wal2json? |
|
How can I compare/modify the JSON when the object is already updated at this point? My use case is more like CDC. We are listening to Postgres updates using wal2json and based on them will be updating another application with the fields that are updated. |
I have similar question: is there a way to receive previous state on the event? Something similar to debezium |
For my understanding, the values available in the SELECT data,
after::jsonb,
before::jsonb,
(after - before)::jsonb as diff
FROM pg_logical_slot_peek_changes('test_slot', NULL, NULL, 'pretty-print', '1', 'add-msg-prefixes', 'wal2json')
CROSS JOIN LATERAL hstore(ARRAY(SELECT jsonb_array_elements_text(data::jsonb->'change'->0->'columnnames')),
ARRAY(SELECT jsonb_array_elements_text(data::jsonb->'change'->0->'columnvalues'))) as after
CROSS JOIN LATERAL hstore(ARRAY(SELECT jsonb_array_elements_text(data::jsonb->'change'->0->'oldkeys'->'keynames')),
ARRAY(SELECT jsonb_array_elements_text(data::jsonb->'change'->0->'oldkeys'->'keyvalues'))) as before
; (Note: this is just a PoC, it only looks to the first change. This can certainly be simplified with more JSON magic. I used a little |
Oooooops! This really works! I solved the problem by alter the table REPLICA IDENTITY by: |
@tbussmann - This works like a charm. It is providing the fields in DIFF that are NULL or changed. Thanks for it. |
This is for the 'UPDATE' events. Is there a way to get a list of fields that are updated rather than having all the values?
There is a discussion here on #188 but it is not very clear if it is possible from wal2json or Postgres itself does not provide any option. Please clarify.
The text was updated successfully, but these errors were encountered: