\set VERBOSITY terse
-- predictability
SET synchronous_commit = on;
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'wal2json');
 ?column? 
----------
 init
(1 row)

-- actions
CREATE TABLE actions (a integer primary key);
INSERT INTO actions (a) VALUES(1);
UPDATE actions SET a = 2 WHERE a = 1;
DELETE FROM actions WHERE a = 2;
TRUNCATE TABLE actions;
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'actions', 'insert, foo, delete');
ERROR:  could not parse value "foo" for parameter "actions"
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '1');
                                                                                                  data                                                                                                   
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"change":[]}
 {"change":[{"kind":"insert","schema":"public","table":"actions","columnnames":["a"],"columntypes":["integer"],"columnvalues":[1]}]}
 {"change":[{"kind":"update","schema":"public","table":"actions","columnnames":["a"],"columntypes":["integer"],"columnvalues":[2],"oldkeys":{"keynames":["a"],"keytypes":["integer"],"keyvalues":[1]}}]}
 {"change":[{"kind":"delete","schema":"public","table":"actions","oldkeys":{"keynames":["a"],"keytypes":["integer"],"keyvalues":[2]}}]}
 {"change":[]}
(5 rows)

SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2');
                                                                            data                                                                             
-------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"I","schema":"public","table":"actions","columns":[{"name":"a","type":"integer","value":1}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"U","schema":"public","table":"actions","columns":[{"name":"a","type":"integer","value":2}],"identity":[{"name":"a","type":"integer","value":1}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"D","schema":"public","table":"actions","identity":[{"name":"a","type":"integer","value":2}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"T","schema":"public","table":"actions"}
 {"action":"C"}
(14 rows)

SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'actions', 'insert');
                                                  data                                                  
--------------------------------------------------------------------------------------------------------
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"I","schema":"public","table":"actions","columns":[{"name":"a","type":"integer","value":1}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
(11 rows)

SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'actions', 'update');
                                                                            data                                                                             
-------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"U","schema":"public","table":"actions","columns":[{"name":"a","type":"integer","value":2}],"identity":[{"name":"a","type":"integer","value":1}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
(11 rows)

SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'actions', 'delete');
                                                  data                                                   
---------------------------------------------------------------------------------------------------------
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"D","schema":"public","table":"actions","identity":[{"name":"a","type":"integer","value":2}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
(11 rows)

SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'actions', 'truncate');
                        data                        
----------------------------------------------------
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"T","schema":"public","table":"actions"}
 {"action":"C"}
(11 rows)

SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'actions', 'update, truncate');
                                                                            data                                                                             
-------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"U","schema":"public","table":"actions","columns":[{"name":"a","type":"integer","value":2}],"identity":[{"name":"a","type":"integer","value":1}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"C"}
 {"action":"B"}
 {"action":"T","schema":"public","table":"actions"}
 {"action":"C"}
(12 rows)

SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');
 ?column? 
----------
 stop
(1 row)

