-- predictability
SET synchronous_commit = on;
SET extra_float_digits = 0;
CREATE TABLE table_truncate_1 (a integer, b text);
CREATE TABLE table_truncate_2 (a integer, b text);
CREATE TABLE table_truncate_3 (a integer, b text);
CREATE TABLE table_truncate_4 (a integer, b text);
CREATE TABLE table_truncate_5 (a integer, b text);
CREATE TABLE table_truncate_6 (a integer, b text);
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'wal2json');
 ?column? 
----------
 init
(1 row)

TRUNCATE table_truncate_1;
BEGIN;
TRUNCATE table_truncate_2;
INSERT INTO table_truncate_1 (a, b) VALUES(1, 'test1');
INSERT INTO table_truncate_3 (a, b) VALUES(2, 'test2');
TRUNCATE table_truncate_3;
INSERT INTO table_truncate_3 (a, b) VALUES(3, 'test3');
COMMIT;
BEGIN;
TRUNCATE table_truncate_4;
ROLLBACK;
BEGIN;
TRUNCATE table_truncate_5, table_truncate_6;
COMMIT;
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '1', 'pretty-print', '1');
                            data                             
-------------------------------------------------------------
 {                                                          +
         "change": [                                        +
         ]                                                  +
 }
 {                                                          +
         "change": [                                        +
                 {                                          +
                         "kind": "insert",                  +
                         "schema": "public",                +
                         "table": "table_truncate_1",       +
                         "columnnames": ["a", "b"],         +
                         "columntypes": ["integer", "text"],+
                         "columnvalues": [1, "test1"]       +
                 }                                          +
                 ,{                                         +
                         "kind": "insert",                  +
                         "schema": "public",                +
                         "table": "table_truncate_3",       +
                         "columnnames": ["a", "b"],         +
                         "columntypes": ["integer", "text"],+
                         "columnvalues": [2, "test2"]       +
                 }                                          +
                 ,{                                         +
                         "kind": "insert",                  +
                         "schema": "public",                +
                         "table": "table_truncate_3",       +
                         "columnnames": ["a", "b"],         +
                         "columntypes": ["integer", "text"],+
                         "columnvalues": [3, "test3"]       +
                 }                                          +
         ]                                                  +
 }
 {                                                          +
         "change": [                                        +
         ]                                                  +
 }
(3 rows)

SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2');
                                                                            data                                                                            
------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"action":"B"}
 {"action":"T","schema":"public","table":"table_truncate_1"}
 {"action":"C"}
 {"action":"B"}
 {"action":"T","schema":"public","table":"table_truncate_2"}
 {"action":"I","schema":"public","table":"table_truncate_1","columns":[{"name":"a","type":"integer","value":1},{"name":"b","type":"text","value":"test1"}]}
 {"action":"I","schema":"public","table":"table_truncate_3","columns":[{"name":"a","type":"integer","value":2},{"name":"b","type":"text","value":"test2"}]}
 {"action":"T","schema":"public","table":"table_truncate_3"}
 {"action":"I","schema":"public","table":"table_truncate_3","columns":[{"name":"a","type":"integer","value":3},{"name":"b","type":"text","value":"test3"}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"T","schema":"public","table":"table_truncate_5"}
 {"action":"T","schema":"public","table":"table_truncate_6"}
 {"action":"C"}
(14 rows)

SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'filter-tables', '*.table_truncate_5');
                                                                            data                                                                            
------------------------------------------------------------------------------------------------------------------------------------------------------------
 {"action":"B"}
 {"action":"T","schema":"public","table":"table_truncate_1"}
 {"action":"C"}
 {"action":"B"}
 {"action":"T","schema":"public","table":"table_truncate_2"}
 {"action":"I","schema":"public","table":"table_truncate_1","columns":[{"name":"a","type":"integer","value":1},{"name":"b","type":"text","value":"test1"}]}
 {"action":"I","schema":"public","table":"table_truncate_3","columns":[{"name":"a","type":"integer","value":2},{"name":"b","type":"text","value":"test2"}]}
 {"action":"T","schema":"public","table":"table_truncate_3"}
 {"action":"I","schema":"public","table":"table_truncate_3","columns":[{"name":"a","type":"integer","value":3},{"name":"b","type":"text","value":"test3"}]}
 {"action":"C"}
 {"action":"B"}
 {"action":"T","schema":"public","table":"table_truncate_6"}
 {"action":"C"}
(13 rows)

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

