LOAD 'test_decoding';

CREATE TABLE foo(a SERIAL PRIMARY KEY, b TEXT);

SELECT pg_create_logical_replication_slot('regression_slot', 'test_decoding');

INSERT INTO foo (b) VALUES ('john');

BEGIN;
SELECT * FROM foo WHERE b = 'john';
SAVEPOINT sp1;
INSERT INTO foo (b) VALUES ('doe');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO foo (b) VALUES ('jane');
END;

SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL);

INSERT INTO foo (b) VALUES ('foo');

BEGIN;
SELECT * FROM foo WHERE b = 'foo' FOR UPDATE;
SAVEPOINT sp1;
INSERT INTO foo (b) VALUES ('bar');
ROLLBACK TO SAVEPOINT sp1;
INSERT INTO foo (b) VALUES ('baz');
END;

SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL);

SELECT pg_drop_replication_slot('regression_slot');
