forked from eulerto/wal2json
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parameter include-column-positions
This parameter is useful to detect schema changes (since attnum are numbered from 1 up). Both formats (1 and 2) are supported although element names are different ("columnpositions" for format 1 and "position" for format 2). Default is false. Issue eulerto#160
- Loading branch information
Showing
5 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
\set VERBOSITY terse | ||
-- predictability | ||
SET synchronous_commit = on; | ||
CREATE TABLE w2j_position (a integer, b integer, primary key(a)); | ||
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'wal2json'); | ||
?column? | ||
---------- | ||
init | ||
(1 row) | ||
|
||
INSERT INTO w2j_position (a, b) VALUES(1,2); | ||
UPDATE w2j_position SET b = 3 WHERE a = 1; | ||
ALTER TABLE w2j_position ADD COLUMN c integer; | ||
ALTER TABLE w2j_position DROP COLUMN b; | ||
INSERT INTO w2j_position (a, c) VALUES(5,6); | ||
UPDATE w2j_position SET c = 7 WHERE a = 5; | ||
-- without include-column-position parameter | ||
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '1'); | ||
data | ||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ||
{"change":[{"kind":"insert","schema":"public","table":"w2j_position","columnnames":["a","b"],"columntypes":["integer","integer"],"columnvalues":[1,2]}]} | ||
{"change":[{"kind":"update","schema":"public","table":"w2j_position","columnnames":["a","b"],"columntypes":["integer","integer"],"columnvalues":[1,3],"oldkeys":{"keynames":["a"],"keytypes":["integer"],"keyvalues":[1]}}]} | ||
{"change":[]} | ||
{"change":[]} | ||
{"change":[{"kind":"insert","schema":"public","table":"w2j_position","columnnames":["a","c"],"columntypes":["integer","integer"],"columnvalues":[5,6]}]} | ||
{"change":[{"kind":"update","schema":"public","table":"w2j_position","columnnames":["a","c"],"columntypes":["integer","integer"],"columnvalues":[5,7],"oldkeys":{"keynames":["a"],"keytypes":["integer"],"keyvalues":[5]}}]} | ||
(6 rows) | ||
|
||
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2'); | ||
data | ||
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
{"action":"B"} | ||
{"action":"I","schema":"public","table":"w2j_position","columns":[{"name":"a","type":"integer","value":1},{"name":"b","type":"integer","value":2}]} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"U","schema":"public","table":"w2j_position","columns":[{"name":"a","type":"integer","value":1},{"name":"b","type":"integer","value":3}],"identity":[{"name":"a","type":"integer","value":1}]} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"I","schema":"public","table":"w2j_position","columns":[{"name":"a","type":"integer","value":5},{"name":"c","type":"integer","value":6}]} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"U","schema":"public","table":"w2j_position","columns":[{"name":"a","type":"integer","value":5},{"name":"c","type":"integer","value":7}],"identity":[{"name":"a","type":"integer","value":5}]} | ||
{"action":"C"} | ||
(16 rows) | ||
|
||
-- with include-column-position parameter | ||
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '1', 'include-column-positions', '1'); | ||
data | ||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ||
{"change":[{"kind":"insert","schema":"public","table":"w2j_position","columnnames":["a","b"],"columntypes":["integer","integer"],"columnpositions":[1,2],"columnvalues":[1,2]}]} | ||
{"change":[{"kind":"update","schema":"public","table":"w2j_position","columnnames":["a","b"],"columntypes":["integer","integer"],"columnpositions":[1,2],"columnvalues":[1,3],"oldkeys":{"keynames":["a"],"keytypes":["integer"],"keyvalues":[1]}}]} | ||
{"change":[]} | ||
{"change":[]} | ||
{"change":[{"kind":"insert","schema":"public","table":"w2j_position","columnnames":["a","c"],"columntypes":["integer","integer"],"columnpositions":[1,3],"columnvalues":[5,6]}]} | ||
{"change":[{"kind":"update","schema":"public","table":"w2j_position","columnnames":["a","c"],"columntypes":["integer","integer"],"columnpositions":[1,3],"columnvalues":[5,7],"oldkeys":{"keynames":["a"],"keytypes":["integer"],"keyvalues":[5]}}]} | ||
(6 rows) | ||
|
||
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'include-column-positions', '1'); | ||
data | ||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ||
{"action":"B"} | ||
{"action":"I","schema":"public","table":"w2j_position","columns":[{"name":"a","type":"integer","value":1,"position":1},{"name":"b","type":"integer","value":2,"position":2}]} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"U","schema":"public","table":"w2j_position","columns":[{"name":"a","type":"integer","value":1,"position":1},{"name":"b","type":"integer","value":3,"position":2}],"identity":[{"name":"a","type":"integer","value":1}]} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"I","schema":"public","table":"w2j_position","columns":[{"name":"a","type":"integer","value":5,"position":1},{"name":"c","type":"integer","value":6,"position":3}]} | ||
{"action":"C"} | ||
{"action":"B"} | ||
{"action":"U","schema":"public","table":"w2j_position","columns":[{"name":"a","type":"integer","value":5,"position":1},{"name":"c","type":"integer","value":7,"position":3}],"identity":[{"name":"a","type":"integer","value":5}]} | ||
{"action":"C"} | ||
(16 rows) | ||
|
||
SELECT 'stop' FROM pg_drop_replication_slot('regression_slot'); | ||
?column? | ||
---------- | ||
stop | ||
(1 row) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
\set VERBOSITY terse | ||
|
||
-- predictability | ||
SET synchronous_commit = on; | ||
|
||
CREATE TABLE w2j_position (a integer, b integer, primary key(a)); | ||
|
||
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'wal2json'); | ||
|
||
INSERT INTO w2j_position (a, b) VALUES(1,2); | ||
UPDATE w2j_position SET b = 3 WHERE a = 1; | ||
ALTER TABLE w2j_position ADD COLUMN c integer; | ||
ALTER TABLE w2j_position DROP COLUMN b; | ||
INSERT INTO w2j_position (a, c) VALUES(5,6); | ||
UPDATE w2j_position SET c = 7 WHERE a = 5; | ||
|
||
-- without include-column-position parameter | ||
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '1'); | ||
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2'); | ||
|
||
-- with include-column-position parameter | ||
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '1', 'include-column-positions', '1'); | ||
SELECT data FROM pg_logical_slot_peek_changes('regression_slot', NULL, NULL, 'format-version', '2', 'include-column-positions', '1'); | ||
|
||
SELECT 'stop' FROM pg_drop_replication_slot('regression_slot'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters