Debian Codegraph @

contrib/test_decoding/sql/decoding_into_rel.sql

raw
1 -- test that we can insert the result of a get_changes call into a
2 -- logged relation. That's really not a good idea in practical terms,
3 -- but provides a nice test.
4
5 -- predictability
6 SET synchronous_commit = on;
7
8 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
9
10 -- slot works
11 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
12
13 -- create some changes
14 CREATE TABLE somechange(id serial primary key);
15 INSERT INTO somechange DEFAULT VALUES;
16
17 CREATE TABLE changeresult AS
18 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
19
20 SELECT * FROM changeresult;
21
22 INSERT INTO changeresult
23 SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
24 INSERT INTO changeresult
25 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
26
27 SELECT * FROM changeresult;
28 DROP TABLE changeresult;
29 DROP TABLE somechange;
30
31 -- check calling logical decoding from pl/pgsql
32 CREATE FUNCTION slot_changes_wrapper(slot_name name) RETURNS SETOF TEXT AS $$
33 BEGIN
34 RETURN QUERY
35 SELECT data FROM pg_logical_slot_peek_changes(slot_name, NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
36 END$$ LANGUAGE plpgsql;
37
38 SELECT * FROM slot_changes_wrapper('regression_slot');
39
40 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
41
42 SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');