PS_NITPICKS_20240627_GENCOLS_V110001_generated_columns.sql

application/octet-stream

Filename: PS_NITPICKS_20240627_GENCOLS_V110001_generated_columns.sql
Type: application/octet-stream
Part: 1
Message: Re: Pgoutput not capturing the generated columns
-- test decoding of generated columns

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

-- column b' is a generated column
CREATE TABLE gencoltable (a int, b int GENERATED ALWAYS AS (a * 2) STORED);

-- when 'include-generated-columns' is not set the generated column 'b' will be replicated
INSERT INTO gencoltable (a) VALUES (1), (2), (3);
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');

-- when 'include-generated-columns' = '1' the generated column 'b' values will be replicated
INSERT INTO gencoltable (a) VALUES (1), (2), (3);
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', include-generated-columns', '1');

-- when 'include-generated-columns' = '0' the generated column 'b' values will not be replicated
INSERT INTO gencoltable (a) VALUES (4), (5), (6);
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', include-generated-columns', '0');

DROP TABLE gencoltable;

SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');