SET synchronous_commit = on;
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');

CREATE TABLE stream_test(data text);

-- consume DDL
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');


-- streaming test for toast changes
ALTER TABLE stream_test ALTER COLUMN data set storage external;
-- consume DDL
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');

analyze;
begin;
INSERT INTO stream_test SELECT repeat('a', 6000) || g.i FROM generate_series(1, 5) g(i);
select pg_sleep(1);
INSERT INTO stream_test SELECT repeat('a', 6000) || g.i FROM generate_series(1, 5) g(i);
end;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');

DROP TABLE stream_test;
SELECT pg_drop_replication_slot('regression_slot');
